These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Sum for repeating fields across multiple pages

scderacjor
Registered: Mar 27 2009
Posts: 123

I have a long list of numbers that users will input (78 numeric fields). They do not all fit onto one page, so I have them split. 26 of them are one page one, and 27-78 are on page two. I want the sum of these fields to show at the bottom of page 2. I have tried two different scripts, but cannot get the sum of the fields from both pages.

Script 1:
Under calculate, I placed the script:

var fields = xfa.resolveNodes("PARIS[*]");
var total = 0;
for (var i=0; i <= fields.length-1; i++) {
total = total + fields.item(i).rawValue;
}
this.rawValue = total;

This only adds the sum of the fields on the page that it appears on (page 2).

Script 2:
Under layout:ready, I placed the script:

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

This script is currently not working, but earlier it was only showing the total of the fields from the first page.

Does anyone have any suggestions or solutions?
Thanks in advance.

My Product Information:
LiveCycle Designer, Windows
nh39
Registered: Feb 19 2010
Posts: 7
A quick way to improve your script 1 is to run on page 1 and pass the value of total to a hidden field on page 2. Then add the hidden's value to the total on page 2.
scderacjor
Registered: Mar 27 2009
Posts: 123
I tried to do that, but the sum value of the fields on page one would not transfer to the second page. Do you have an example of this in scripting? Maybe I was doing it wrong..?

Thanks!
nh39
Registered: Feb 19 2010
Posts: 7
Try this and let's see if it'll work.
On page 1, add another numeric field to temporarily hold the total of the fields on page 1. Let's call it sub_total and make it hidden; so users won't see it. Use the same script 1 to get the total on page 1.
On page 2, still using the same script for total (the grand total of both pages). However, at the end of the script, below this.rawValue = total, add this line:
total = total + %FormName%.%PageNumber.sub_total.rawValue;

Where %FormName% is the name of your form in the hierarchy and %PageNumber% is the name of your page 1. It looks like you have labeled your form and the objects on the form. If not, I suggest you do so before proceed.

I hope this message makes sense and is helpful to you. I don't know your skill level on LiveCycle Designer; so I rather be a little wordy and thorough.