Calculate grand total across multiple spawned pages.
Hello all. I have a form with a single page template. Users can spawn new pages as needed. Each page has a Page Total field and a Grand Total field.
I would like the GT field on each page to collect and add up the values of all of the PT fields in the document. The trouble I'm having is that I can't seem to get the GT fields to grab page totals from other pages. Each GT field only displays the total of the page it's on. This is the calculation script I'm using:
var prefix = "";
var nameParts = event.target.name.split(".");
if (nameParts.length > 2) {
prefix = nameParts[0] + "." + nameParts[1] + ".";
}
var grandTotal;
for (i = 0; i < this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if (fname == prefix + "pgtotal")
{
grandTotal += this.getField(this.getNthFieldName(i)).value;
}
}
event.value = grandTotal;
What am I missing? Is there an easier way to go about calculating a grand total for the document to display on every page?
