Calculate Negative Form Values in Adobe Acrobat with JavaScript
Question details
Calculate the absolute value of a negative PDF form input and divide that result by 65 in a separate field.

- 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.
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.
Add calculation scripts to FieldB and FieldC
Use separate custom calculation scripts so each output field updates from its source field.
In Acrobat, open the PDF and select All tools > Prepare a form. Locate FieldA, FieldB, and FieldC in the form.
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;
Open FieldC Properties and choose Calculate > Custom calculation script > Edit. Enter: var b = Number(this.getField("FieldB").value); event.value = b > 0 ? b / 65 : "";
In Prepare a form, open the More or options menu and select Set Field Calculation Order. Move FieldB before FieldC, then confirm the order.
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.

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.

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.




