Copy link to clipboard
Copied
I have a list of costs on a final summary page. Based off radio buttons that are clicked on previous pages, a specific product's "total" field will hide or show on that last summary page. I was successful in creating a field that calculated the sum of all the product totals - the visible fields on the summary page - with this script:
(function () {
var f, sum = 0;
// Loop through the text fields
for (var i = 1; i < 9; i += 1) {
// Get a reference to the current text field
f = getField("total." + i);
// If the current field is visible (and printable), numerically add it's value to the running sum
if (f.display === display.visible) {
sum += +f.value;
}
}
// Set this field's value to the sum
event.value = sum;
})();
The fields are labeled total.1, total.2, total.3, total.4, total.5, total.6, total.7, total.8.
The final sum field is labeled total.9
All of those are set as Read Only.
However, there is a delay in the calculation. When I click a certain radio button to unhide that products "total" field, the summary calculation doesn't add up correctly. If I click a new field it will calculate the previous radio button's selection. The confusing part is I have these fields in the correct order in the Field Calculation Order. Could there be any other reason for the delay?
I do have it set where the user can type in the quantity and individual cost of a product. That is what gives the product "total" fields (total.1, total.2, total.3, total.4, total.5, total.6, total.7, total.8) their value. Could that possibly be the reason?
Hi ncc77,
If I understand the issue correctly, the value of 'total.9' is incorrect even when all the fields above them (total.0, total.1 ... total.8) are displaying correct values. This issue is occurring because of the execution order of the 'Calculate' events vs 'Mouse Up' events.
The javascripts used in your radio buttons to hide/unhide the total.0 ... total.8 fields are set with a trigger of 'Mouse Up' event, whereas, field calculation for total.9 is set on 'Calculate' event. In Acrobat, 'Calc
...Copy link to clipboard
Copied
It's hard to say what's wrong without looking at the form. If you can post it somewhere, we can take a look.
Copy link to clipboard
Copied
Dropbox - SAS_Proposal_MasterForm.pdf
Page 1 has the toilet selection, page 2 has the showerhead and aerator selection. Page 5 is the summary of all 4 products. (the blue number should be the sum of all 4 product selections.)
Right now I have the radio button values at a specific number to show water savings so I can't use that value to calculate cost. I use a script in the radio button this.getField("fieldname").display = display.visible; to hide/display certain totals on the 5th page.
Copy link to clipboard
Copied
Hi ncc77,
If I understand the issue correctly, the value of 'total.9' is incorrect even when all the fields above them (total.0, total.1 ... total.8) are displaying correct values. This issue is occurring because of the execution order of the 'Calculate' events vs 'Mouse Up' events.
The javascripts used in your radio buttons to hide/unhide the total.0 ... total.8 fields are set with a trigger of 'Mouse Up' event, whereas, field calculation for total.9 is set on 'Calculate' event. In Acrobat, 'Calculate' events takes priority over any 'Mouse Up' events. This means that the (total.9) field's value is calculated first after which the script is executed which hides/unhides the total.0 .. total.8 fields.
Possible solutions:
- Change the event trigger to 'Mouse Down' or 'On Focus' depending on your requirement, OR
- As mentioned by Bernd below, add this.calculateNow(); at the end of the scripts to force recalculation.
Let us know if this solves your problem.
Copy link to clipboard
Copied
Thank you! I didn't realize Calculate events took priority over 'Mouse Up' events. That makes sense! I made both edits as you suggested and it works beautifully. I appreciate it!
Copy link to clipboard
Copied
In the scripts for the radio buttons add this:
calculateNow();
Copy link to clipboard
Copied
Hi George,
We're you able to take a look at the document?