Keep an Adobe Acrobat Calculation Field Blank Until Both Inputs Are Entered
Question details
Keep a calculated PDF form field blank until both source fields have values.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form subtracts one input field from another in a calculated result field.
- Observed behavior
- The result field displays zero before both source fields are filled in.
Open the form in a version of Acrobat that can edit form fields, and note the exact names of the two input fields. The example below assumes both inputs are numeric and subtracts the second value from the first.
Add a custom calculation script to the result field
Use this script when the result should remain blank until both input fields contain values.
Open the PDF in Adobe Acrobat and select Tools > Prepare a Form, or choose Prepare a form from the available tools.
Double-click each source field and check its name in the General tab of Field Properties. Note the exact spelling, spaces, and capitalization.
Double-click the result field, open the Calculate tab, select Custom calculation script, and click Edit.
Paste the following script into the JavaScript editor, replacing both example names with your actual field names: (function () { var s1 = getField("Form Field 1").valueAsString; var s2 = getField("Form Field 2").valueAsString; if (s1 && s2) { event.value = Number(s1) - Number(s2); } else { event.value = ""; } })();
Click OK to close the script editor and field properties, then save the PDF. Enter values in both source fields and clear either one to verify that the result becomes blank.
Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative for everyday document and PDF work, with a familiar interface and support for common Microsoft Office formats to help you migrate existing files. Use Adobe Acrobat for the custom PDF calculation script described above.

Frequently Asked Questions
Where do I find the custom calculation script setting in Acrobat?
Open Prepare a Form, double-click the result field, and select Calculate > Custom calculation script > Edit.
Why does the result stay blank after I enter both values?
Check the source field names in Field Properties and make sure they match the names in the script exactly, including spaces and capitalization. Also test in a PDF viewer that supports form JavaScript.
Will the script calculate if one input is zero?
Yes. An entered zero is read as the nonempty string "0", so the calculation runs once the other field also has a value.
How can I change the subtraction to addition?
In the custom calculation script, replace the minus sign in Number(s1) - Number(s2) with a plus sign, then save and test the form.




