Expand my Community achievements bar.

## Adding multiple numeric fields in a expanding table

Level 2

Hi Alll,

I have created a table where the user can add multiple rows. One column of this table contains numeric fields. At the bottom of this column I have a numeric field where I want to auto sum the rows above.

I have managed to achieve this in a table with fixed rows however I cant seem to do the same in the table where the end user can add rows. Please can someone inform me if there is any javascript available to avhieve this.

Lee

5 Replies

Former Community Member

Hi Lee,

The pseudocode goes something like this:

1) check the number of rows/instances added.

2) Get the value of the numeric field of every row/instance using "for" loop (loop starting from 0 till < number of rows)

3) Keeping adding the values of numeric field of every instance inside the loop.

You can mail me the form @ kvdvijaykumar@gmail.com if you want any help in detailed code.

Thanks,

VJ.

Level 5

There are several possibilities to solve an addition in a dynamic table.

With Javascript do the following:

`var page = xfa.layout.page(this)-1;var fields = xfa.layout.pageContent(page , "field", 0);this.rawValue = 0;var total = 0;for (var i=0; i <= fields.length-1; i++) {    if (fields.item(i).name == "summe")     {        total = total + fields.item(i).rawValue;    }}this.rawValue = total;`

https://workspaces.acrobat.com/?d=PtkT0VkRuIsKJOgnmagKWw

You have to change "summe" in yours. If your field for the addition called amount you have to change summe into amount.

You can do the same with Formcalc. Then you have to use the following script in the calculate-event from your target field:

`//Zeile1 means Row1 - I come from Germany //if you create instances of Row 1 you have to write this\$ = Sum(Zeile1[*].summe)//if you have several instances of summe..means summe[0], summe[1]..then you have to write\$ = Sum(summe[*])`

https://workspaces.acrobat.com/?d=eJ2yV-EoAI*Pks08YegPJQ

Kind regards Mandy

Former Community Member

Hi Lee,

Add the following code on the layout:ready event of the textfield that should display the total.

var count = xfa.resolveNode("form1.AuditResults.summaryrow").instanceManager.count;

var total = 0;

for(var i=0;i<count;i++)

{

var currentInstanceNumber =            xfa.resolveNode("form1.AuditResults.summaryrow["+i+"].NumercField15").rawValue;

total = total+currentInstanceNumber;

}

this.rawValue = total;

Not sure if there is any easy way.

Level 10

The easiest way is the FormCalc version Mandy suggested.