Expand my Community achievements bar.

SOLVED

Adding up values in a repeting row

Avatar

Level 2

I have a table that currently consists of 3 rows.

BagNumber of Items in Bag
A6
B12
Total

I have a button which allows the user to add more rows to the table, a maximum of 10 rows can be added.  I would like to be able to add up all the numbers, in the total cell.  How do I add up all the numbers for cells that do not currently exist?

For example:  If today I have 2 bags..Bag A has 6 items in it and Bag B has 12 items in it.  But tomorrow I have 7 bags, each with a different number of items.

What is the code I can write in my total box that will add up the number of items in a bag, for up to 10 bags?  What I don't want is all 10 rows static on the page, if the table only needs to consist of 2 rows, that is all that I would like to see, and I don't want a big gap (8 rows) between my values and the total box.

I can share my form if necessary.

Any help would be appreciated....greatly!

1 Accepted Solution

Avatar

Correct answer by
Level 2

You need to use Sum in the calculate event of the total field.

<calculate>

                        <script>Sum(Table1.Row1[*].items[*])

</script>

                     </calculate>

That's it.  It cycles through the rows every time you leave the items field and recalculates.

View solution in original post

5 Replies

Avatar

Correct answer by
Level 2

You need to use Sum in the calculate event of the total field.

<calculate>

                        <script>Sum(Table1.Row1[*].items[*])

</script>

                     </calculate>

That's it.  It cycles through the rows every time you leave the items field and recalculates.

Avatar

Level 2

Thank you for your response, that script isn't working.

I put in 5 for the first value, and 5 for the second, the total is coming up 5.

Here is my script: 

Sum(SeedItem1.Row2[

*].NumBushels[*])

Avatar

Level 2

What field are you adding the calculate event to?  Is the total field inside the same table as the rows you're counting?

I double-checked my code (that works in Acrobat and Reader), and I have quite a few calculate fields.  The only scripting I used for any of it was that tiny bit - table_name.row_name[*].cell_name[*].

Avatar

Level 2

The total field is in the table, it is in the footer row.  The calculation is occuring in the total field.

Avatar

Level 2

I figured it out.....I had changed the name name of Row2[1] to Row 3...problem fixed, I just changed Row3 back to Row2[1].

Thanks