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

323
Visualizações
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 Respostas
Responde à pergunta

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 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