Create an Acrobat Calculation Script to Add Multiple PDF Fields
Question details
The user needs a custom Acrobat calculation script that adds ten PDF form fields.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs to calculate a total from fields named TaxDue1 through TaxDue10.
- Observed behavior
- The existing script uses commas instead of addition operators and incorrectly references some fields, so it calculates only the first value.
Open the form in an Acrobat edition that supports editing PDF forms. In Prepare a Form, verify that the ten source fields are named exactly TaxDue1 through TaxDue10 and identify the field that will display the total.
Add the fields with an Acrobat custom calculation script
Use this method to sum all ten TaxDue fields and leave the result blank when the total is zero.
The script retrieves each field with getField() and adds its numeric value. Blank or nonnumeric values contribute zero; all ten named fields must exist.
In Acrobat, open the PDF and choose All tools > Prepare a form. Double-click the field that should display the total.
In the field properties, open the Calculate tab, select Custom calculation script, and click Edit. Enter: var total = 0; for (var i = 1; i <= 10; i++) total += Number(this.getField("TaxDue" + i).value) || 0; event.value = total ? total : "";
Close the field properties, then use More > Set field calculation order in Prepare a Form. Place the total field after all calculated TaxDue fields and confirm the order.
Preview the form, enter values in several TaxDue fields, and check that the total updates to their sum.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative for working with PDFs and Office documents in a familiar interface. Its Microsoft Office format compatibility can help you migrate existing files; it does not fix or replace Acrobat custom calculation scripts.

Frequently Asked Questions
Why does my Acrobat script calculate only the first field?
Check the script in the total field's Properties > Calculate tab. Use addition to combine values and call this.getField() for each field, or use a loop to retrieve TaxDue1 through TaxDue10.
What happens if a TaxDue field is blank?
The script treats blank and nonnumeric values as zero. The field itself must still exist with the exact name expected by getField().
Why is the total field blank when the sum is zero?
The expression event.value = total ? total : "" displays a blank for a zero sum. Change it to event.value = total; in the custom calculation script to display 0.
Where do I change the field calculation order?
In Acrobat's Prepare a Form tool, choose More > Set field calculation order. Place the total field after any TaxDue fields that are themselves calculated.




