Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda