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

298
Visualizações
How to get this HTML table's text box value using JS?

I've tried different approaches, but I'm missing something crucial:

Here's a Fiddle version

function saveData() {
  var table = document.getElementById("dtable");

  var [, ...tr] = table.querySelectorAll("tr");
  var tableData = [...tr].map(r => {
    var td = r.querySelectorAll("td");
    return [...td].map((c, j) => j < 6 ? c.innerHTML : j == 6 ? c.querySelectorAll("select")[0].value : j == 7 ? c.querySelectorAll('comments')[0].value);
  })
  tableData = tableData.filter(e => e[6] != 'empty');

}

Note for column counting purpose: The first column of the table is hidden.

This is the column whose data is to be grabbed:

<td><input type="text" name="comments" style="width:99%;"></td>

Appreciate your help!

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

0

Here is the solution, which was given by a good soul on Fiddle:

function saveData() {
  var table = document.getElementById("dtable");

  var [, ...tr] = table.querySelectorAll("tr");
  var tableData = [...tr].map(r => {
    var td = r.querySelectorAll("td");
    return [...td].map((c, j) => j < 6 ? c.innerHTML : j == 6 ? c.querySelectorAll("select")[0].value : j == 7 ? c.querySelectorAll('input[name="comments"]')[0].value : '')})
  tableData = tableData.filter(e => e[6] != 'empty');
}

and this is what's changed:

From:

c.querySelectorAll('comments')[0].value

To

c.querySelectorAll('input[name="comments"]')[0].value

Not sure why he/she wouldn't post the answer himself/herself.

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