Fix an Acrobat PDF Form Calculation Script That Returns Blank
Question details
Correct a PDF form calculation so it divides two field values and returns zero when the numerator is blank or zero.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A calculated form field should divide a numerator by a denominator while handling blank or zero inputs.
- Observed behavior
- The custom calculation script returns a blank value instead of the expected result.
Open the PDF in an Acrobat edition that lets you edit form fields, and check the exact names of the numerator and denominator fields. Make sure the PDF permits form editing.
Replace the Custom Calculation Script with Numeric Checks
Use this script to convert field values to numbers and return zero when either value is blank, invalid, or zero.
In Adobe Acrobat, open the PDF and choose All tools > Prepare a form.
Double-click the field that should display the calculated result, then select the Calculate tab.
Select Custom calculation script and click Edit. Replace the existing code with: var numerator = Number(getField("GOALPATIENTSRow1_2").value) || 0; var denominator = Number(getField("GOALDAYSRow1_2").value) || 0; event.value = (numerator === 0 || denominator === 0) ? 0 : numerator / denominator;
Replace the names inside getField() if your fields have different names. Close the properties, then enter test values in the form, including a blank numerator, a zero denominator, and two nonzero numbers.

Work with PDF and Office Files in WPS Office
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 Acrobat-specific form calculation scripts.

Frequently Asked Questions
Where do I put the calculation script in Acrobat?
Choose All tools > Prepare a form, double-click the result field, and open Calculate > Custom calculation script > Edit.
Why does the script check the denominator for zero?
Dividing by zero does not produce a usable form result. The script sets event.value to zero when the denominator is blank, invalid, or zero.
How do I find the correct field names?
In Prepare a form, double-click each input field and check its name in the field properties. Use those exact names in the getField() calls.
What if the result does not update after I change an input?
Check Acrobat's Forms preferences to make sure automatic field calculation is enabled. If the input fields are themselves calculated, also check the field calculation order in Prepare a form.




