PDF Editing Issues

Create an Acrobat Calculation Script to Add Multiple PDF Fields

Chanuka GeekiyanageChanuka Geekiyanage Nov 19, 2026 868 views

Question details

The user needs a custom Acrobat calculation script that adds ten PDF form fields.

Create an Acrobat Calculation Script to Add Multiple PDF 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the total field properties

In Acrobat, open the PDF and choose All tools > Prepare a form. Double-click the field that should display the total.

2
Enter the script

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 : "";

3
Set the calculation order

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.

4
Test the form

Preview the form, enter values in several TaxDue fields, and check that the total updates to their sum.

Add the fields with an Acrobat custom calculation script
Displaying a zero total: The final line leaves the total field blank when the sum is zero. To display 0 instead, replace it with event.value = total;
Free Microsoft Office alternative

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.

Open and work with PDF documents alongside other filesCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXFamiliar interface for moving from Microsoft OfficeFree and lightweight office suite
microsoft office alternative - wps office

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.