PDF Editing Issues

Calculate Negative Form Values in Adobe Acrobat with JavaScript

Steve KSteve K Nov 19, 2026 868 views

Question details

Calculate the absolute value of a negative PDF form input and divide that result by 65 in a separate field.

Calculate Negative Form Values in Adobe Acrobat with JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form has an input field named FieldA and calculated fields named FieldB and FieldC.
Observed behavior
FieldB should show the positive equivalent of a negative FieldA value, or zero otherwise. FieldC should show FieldB divided by 65 when FieldB is greater than zero and remain blank otherwise.
Before you start

Open the PDF in Adobe Acrobat and confirm that the form fields are named exactly FieldA, FieldB, and FieldC. Make sure JavaScript is enabled in Acrobat's Preferences under JavaScript.

Solution 1Recommended

Add calculation scripts to FieldB and FieldC

Use separate custom calculation scripts so each output field updates from its source field.

1
Open form editing

In Acrobat, open the PDF and select All tools > Prepare a form. Locate FieldA, FieldB, and FieldC in the form.

2
Calculate FieldB

Open FieldB Properties, select the Calculate tab, choose Custom calculation script, and click Edit. Enter: var n = Number(this.getField("FieldA").value); event.value = isFinite(n) && n < 0 ? -n : 0;

3
Calculate FieldC

Open FieldC Properties and choose Calculate > Custom calculation script > Edit. Enter: var b = Number(this.getField("FieldB").value); event.value = b > 0 ? b / 65 : "";

4
Set calculation order

In Prepare a form, open the More or options menu and select Set Field Calculation Order. Move FieldB before FieldC, then confirm the order.

5
Save and test

Save the PDF, exit form editing, and enter -130 in FieldA: FieldB should show 130 and FieldC should show 2. Also test a positive number, zero, and a blank value; FieldB should show 0 and FieldC should be blank.

Add calculation scripts to FieldB and FieldC
Check the PDF viewer: The calculations require a PDF viewer that supports Acrobat form JavaScript and has JavaScript enabled. Some browser-based or third-party viewers may not run the scripts.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free-to-download, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes moving everyday files straightforward, but it does not replace Acrobat's form JavaScript editor; some PDF editing features may require a subscription.

Open and review PDF documents alongside other filesCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar document, spreadsheet, and presentation interfaceLightweight, free-to-download office suite
microsoft office alternative - wps office

Frequently Asked Questions

What happens when FieldA is positive or blank?

The FieldB script sets FieldB to 0. Because FieldB is not greater than zero, the FieldC script sets FieldC to an empty string.

Why is FieldC showing an old result?

In Acrobat's Prepare a form tool, open Set Field Calculation Order and ensure FieldB is calculated before FieldC. Also check that the field names in both scripts match the actual field names.

How can I change the number of decimal places in FieldC?

Open FieldC Properties, select the Format tab, choose a number format, and set the desired decimal places. This changes the displayed result, not the division in the script.

Will the calculations work in a browser PDF viewer?

Not necessarily. The viewer must support Acrobat form JavaScript. Test the saved PDF in Acrobat with JavaScript enabled under Preferences > JavaScript.