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

328
Vistas
How to SUM the inputs inside all rows?

I'm using a script to generate a new row with value each time, those values goes to a table as an input All what I want is a button to sum all values in those inputs in one input.

Total input id is valueall

This is the code I have used:

            function updateSubTotal() { 
            var table = document.getElementById("empTable");
            for (var i = 0, row; row = table.rows[i]; i++) {
                for (var cell; cell = row.cells[1];){
                var inp = cell.children[0];
                }
             }     
             document.getElementById("valueall").value = inp.value;
            }  

That code works fine when I put it under var inp = cell.children[0]; but it keeps repeating the same row value as loop.

Here's the table:

 <form>
        <table id="empTable">
            <tr>
                <td>Products in the invoice</td>
            </tr>
        </table>
 </form>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're not summing anything. You need to actually sum up the contents of the <input> fields:

function updateSubTotal() { 
  var sum = 0;
  var table = document.getElementById("empTable");
  for (var i = 0, row; row = table.rows[i]; i++) {
    for (var cell; cell = row.cells[1];){
      var inp = cell.children[0];
      sum += Number(inp.value)
    }
  }     
  document.getElementById("valueall").value = sum;
}
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