PDF Editing Issues

Fix an Acrobat PDF Calculation Script After Reopening a Form

Kushani NimanthikaKushani Nimanthika Nov 24, 2026 868 views

Question details

Fix a custom calculation in an Acrobat PDF form that stops working after the file is reopened or the form is cleared.

Fix an Acrobat PDF Calculation Script After Reopening a Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form divides one field value by another using a custom JavaScript calculation.
Observed behavior
The calculation initially works but fails after the PDF is reopened or the form is cleared. The script does not handle empty, invalid, or zero values.
Before you start

Open the PDF in Acrobat and confirm the exact names of the numerator and divisor fields in Prepare a Form. Check whether commas in the field values are thousands separators or decimal separators before changing the script.

Solution 1Recommended

Validate the field values in the Acrobat calculation script

Use this method to diagnose JavaScript errors and prevent invalid values or a zero divisor from breaking the calculation.

The example below removes commas as thousands separators. Do not use that conversion unchanged if your form uses commas as decimal separators.

1
Check the JavaScript console

Open the PDF in Acrobat and press Ctrl+J to open the JavaScript console. Reproduce the problem by clearing or reopening the form, then check the console for errors.

2
Open the calculation script

Open Prepare a Form, select the calculated result field, and open its Properties. On the Calculate tab, select Custom calculation script and click Edit.

3
Replace and adapt the script

In the script editor, replace the existing calculation with the following. Change the two field names to match your form exactly: var numeratorField = this.getField("Remaining Balance 3"); var divisorField = this.getField("Divide by 2"); var numeratorText = numeratorField ? numeratorField.valueAsString.replace(/,/g, "") : ""; var divisorText = divisorField ? divisorField.valueAsString.replace(/,/g, "") : ""; var numerator = Number(numeratorText); var divisor = Number(divisorText); if (numeratorText.replace(/\s/g, "") !== "" && divisorText.replace(/\s/g, "") !== "" && isFinite(numerator) && isFinite(divisor) && divisor !== 0) { event.value = numerator / divisor; } else { event.value = ""; }

4
Save and test the form

Confirm the script and field properties, then use File > Save. Test valid values, an empty field, a zero divisor, and a value with a thousands separator; clear the form and reopen the PDF to test again.

Validate the field values in the Acrobat calculation script
Check field names: If the result stays blank, verify both field names in Prepare a Form and check the JavaScript console for errors. The script clears the result when either value is empty or invalid, or when the divisor is zero.
Free Microsoft Office alternative

Work with PDFs and office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. Its format support helps make moving everyday documents between office suites straightforward. Use Acrobat to diagnose and edit the custom PDF JavaScript described above.

Open and review PDF documents alongside office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for everyday document tasksFree and lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Where can I find errors in an Acrobat calculation script?

Press Ctrl+J in Acrobat to open the JavaScript console, then reproduce the problem and inspect the reported errors.

Why does clearing the form affect the calculation?

Clearing the form can leave the numerator or divisor empty. The script should check both values before dividing and clear the result when the inputs are invalid.

Can a comma in a number cause a calculation error?

Yes. JavaScript's Number conversion does not automatically interpret a value such as 1,000 as a number. Remove commas only when they represent thousands separators; decimal-comma formats need different handling.

Where do I edit a custom calculation in Acrobat?

Open Prepare a Form, open the calculated field's Properties, and choose Calculate > Custom calculation script > Edit.