Keep an Acrobat PDF Form Calculation Blank When Inputs Are Empty
Question details
Keep a calculated PDF form field blank until both input fields have values.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form calculates column3 minus column2 plus 1 in a result field.
- Observed behavior
- The result field displays 1 when the input fields are blank.
Open the PDF in Adobe Acrobat and confirm the exact names of the two input fields and the result field in Prepare a form. Check that the input fields have no default value if they should start blank.
Add a custom calculation script to the result field
Use a custom calculation to leave the result blank until both input fields contain data.
In Acrobat, open the PDF and select All tools > Prepare a form.
Right-click the result field, such as column4, and select Properties. Open the Calculate tab.
Select Custom calculation script, click Edit, and enter the following script. Replace column3 and column2 with your exact input field names if they differ: var column3 = this.getField("column3").valueAsString; var column2 = this.getField("column2").valueAsString; if (column3 === "" || column2 === "") { event.value = ""; } else { event.value = (Number(column3) - Number(column2)) + 1; }
Click OK to save the script, close the field properties, and use Preview in Prepare a form. Test both blank fields, each field blank individually, and two numeric inputs, including zero.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Microsoft Office files. It can help you move between document formats, but it does not replace Acrobat's custom form calculation editor.

Frequently Asked Questions
Why does the calculation show 1 when both fields are blank?
The calculation can treat blank inputs as zero, making the expression 0 minus 0 plus 1 equal 1. A custom calculation script can check for blank inputs before calculating.
Where do I put the calculation script in Acrobat?
Open All tools > Prepare a form, right-click the result field, and choose Properties. On the Calculate tab, select Custom calculation script and click Edit.
Will the script calculate when an input is zero?
Yes. The script checks the fields' string values for an empty string, so a value of 0 is treated as an input rather than as a blank.
What should I check if the result is still incorrect?
In Prepare a form, verify that the field names in the script match the input fields exactly. Test the number format as well: separators such as commas may not be accepted by JavaScript's Number function.




