Fix an Acrobat JavaScript Calculation for Three PDF Form Fields
Question details
The user needs an Acrobat form calculation that sums three fields regardless of entry order and hides the TDH result when a value is missing.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form calculates total dynamic head from the Lift, Friction Loss, and System Head fields.
- Observed behavior
- The form freezes when values are entered in a different order, and the TDH field needs to be hidden if an input is missing.
Open the PDF in Acrobat and confirm that the form fields are named exactly Lift, Friction Loss, System Head, and TDH. Check that the input fields start blank if missing values should keep TDH hidden.
Update the TDH calculation script
Use a single calculation that converts the inputs to numbers and hides TDH until all three contain valid values.
The second of two consecutive event.value assignments overwrites the first. Also, adding text values can concatenate them instead of calculating a numeric sum.
The script below accepts zero as a valid value but hides TDH for blank or nonnumeric inputs. Enter plain numbers without commas or unit labels.
In Acrobat, open the PDF and choose Prepare a form. Open the TDH field's Properties, select Calculate, and choose Custom calculation script, then click Edit.
Replace the calculation script with: var lift = this.getField("Lift").valueAsString; var friction = this.getField("Friction Loss").valueAsString; var head = this.getField("System Head").valueAsString; var tdh = this.getField("TDH"); if (!/\S/.test(lift) || !/\S/.test(friction) || !/\S/.test(head) || !isFinite(Number(lift)) || !isFinite(Number(friction)) || !isFinite(Number(head))) { event.value = ""; tdh.display = display.hidden; } else { event.value = Number(lift) + Number(friction) + Number(head); tdh.display = display.visible; }
Confirm the script, close the field properties, and save the PDF. Enter the three values in different orders, then clear one input to check that TDH becomes hidden.
If the form still freezes or shows an unexpected result, review the other fields' calculation scripts and the form's field calculation order in Prepare a form. Remove conflicting calculations and test again.

Use WPS Office for Everyday PDF and Document Work
WPS Office is a free, lightweight alternative for everyday document work, with a familiar interface and support for common Office formats to make migration easier. It does not fix or debug Acrobat-specific JavaScript.

Frequently Asked Questions
Why does the form join numbers instead of adding them?
Field values can be treated as text. In the TDH custom calculation script, use Number() on each input before adding the values.
Where do I edit the TDH calculation in Acrobat?
Choose Prepare a form, open TDH Properties, and select Calculate. Choose Custom calculation script and click Edit.
Will TDH stay visible if one input is zero?
Yes. The example checks for blank and nonnumeric values, so zero is accepted as a valid input. Clear an input to hide TDH.
Why might the calculation still fail in another PDF viewer?
Some viewers do not support Acrobat JavaScript or scripted field visibility. Test the form in Acrobat with JavaScript enabled and verify the field names and calculation order.




