Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!