Adding total of rows

Hi

I have a loop for adding rows in a table. The rows also have a column/field called ‘fee’. I want to add the fee and display as total.

I have used the following loop for the sum

for (i = 0; i < rowCount; i++) {
tableRows[i].fee = 100;
totalfee = totalfee + tableRows[i].fee;
$w (“#text8”).text = totalfee;

The above code is returning text values in the text8 box and not the total of all ‘fee’. How can I display the total/sum of all ‘fee’?

Hey

It’s really hard to find a problem without context
Can you please share a link to the site with the code? You can also create new site especially for this.

Please see test page

I want to show the sum of ‘Fee’ in a text field anywhere on the page.

Hi Suneel,

If your ‘fee’ field a number or a string?
For numbers, this loop will work:

let total = 0;
for (let i = 0; i < tableRows.length; i++) {
    total += tableRows[i];
}
$w ("#text8").text = total;

if you have a string there, you need to convert it:

let total = 0; 
for (let i = 0; i < tableRows.length; i++) {     
    total += parseInt(tableRows[i], 10); 
} 
$w ("#text8").text = total;

Hope this helps,
Liran.