Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adding multiple numeric fields in a expanding table

Avatar

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.

Many thanks in advance

Lee

5 Replies

Avatar

Level 4

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.

Avatar

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

Helpful?

Kind regards Mandy

Avatar

Level 4

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.

Helpful??????????????

Avatar

Level 10

The easiest way is the FormCalc version Mandy suggested.

For your sample it's better to use resolveNodes() instead of resolveNode(). See: http://blogs.adobe.com/formfeed/2011/06/resolvenode-vs-resolvenodes.html

Avatar

Level 1

This was very helpful Mandy!  I am left with one more problem.  How can I get it to prompt the user if the total becomes larger than 100?

something like Total value can not be larger than 100.

expandingtable.JPG

Thanks for any help you can give!

Here is my version of the code you gave

$ = Sum(FabricDeatilsRow1[*].FabricPercent5);