Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Generate a row with empty cells and a filled drop down list

I need to generate in JavaScript a new row on a table with a (dropdown list) who is already filled and empty other cells and I want the function to work no matter which cells is the DropDown list in the row.

Here's my function :

function AddRows(tableid){
    var table = document.getElementById(tableid);
  var tbody = table.tBodies[0];
  var rowCount = tbody.rows.length;
  var row = table.insertRow(rowCount);
  var lastRow = tbody.rows[rowCount-1];
  var clonedRow = lastRow.cloneNode(true);
       var editContent = !row.isContentEditable;
        row.contentEditable = editContent;
    row.setAttribute('onkeyup', "Disabled();");
    row.setAttribute('onclick', "SetSelectedRow(this)");
    row.setAttribute('id', 'Combo_row'+(row.rowIndex - 1)); //Set the id of the row
    row.setAttribute('class', 'default');

  for(i=0; i< clonedRow.cells.length;i++){
  var clonedcell = clonedRow.cells[i];
    if(!clonedcell.children[0]){
        clonedcell.innerText= "";
    }
  }
  tbody.appendChild(clonedRow);

}

And here's what i get : enter image description here

The problem is that when i add a row it keep what i added on the input and i only want to keep whats in the dropdown list the other cell should be empty cause i want the user to insert other information

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found a solution ! If someone need here's my working function :

/* function to add row with a select */
// lPos : list of cells position in the row to reset
function addSelect(SelectTableId, lPos) {
    var Table = document.getElementById(SelectTableId);                 // Get the table id
    var R = document.querySelectorAll('tbody .AddRowClass')[0];         // Get the row className
    var C = R.cloneNode(true);                                          // Clone the row
    for (let i = 0; i< lPos.length; i++){                               // Clear selected cells of the row
        C.children[lPos[i]].textContent = ""
    }
Table.appendChild(C);                                                   // Display the new row with filled dropdown list and empty cells

} 
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda