How to Automatically Populate Pass or Fail Fields in Acrobat PDF Forms
Question details
The user needs a PDF form to automatically display "Pass" or "Fail" based on a calculated ratio, while avoiding calculation errors when input fields are empty.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up conditional text outputs in a dynamic PDF form based on the mathematical result of other fields.
- Observed behavior
- The form incorrectly displays "NaN" or a number-format error when input fields are left blank, due to division by zero during the automatic calculation process.
Ensure you have access to the 'Prepare Form' tool in your PDF editor and note the exact field names (e.g., 'R' for the ratio result) before adding scripts.
Use a Custom Calculation Script with Empty Field Checks
Apply a custom JavaScript calculation to your text fields that verifies if the input is empty before calculating, preventing division by zero and returning the correct Pass/Fail string.
By default, PDF forms attempt to calculate formulas even when fields are empty. Empty fields are treated as zero, which causes a 'NaN' (Not a Number) error if your formula involves division. To fix this, you must write a script that explicitly checks for an empty string before processing the math.
Navigate to 'Tools' and select 'Prepare Form' to enter editing mode for your PDF fields.
Right-click on your designated 'Pass' text field and select 'Properties' from the context menu.
Go to the 'Calculate' tab, choose 'Custom calculation script', and click 'Edit'. Paste the following code: var r = this.getField("R").valueAsString; event.value = (r != "" && Number(r) <= 0.075) ? "P" : "";
Repeat the process for your 'Fail' text field. Use a similar script but change the condition to check if the number is greater than 0.075: var r = this.getField("R").valueAsString; event.value = (r != "" && Number(r) > 0.075) ? "F" : "";

Create and Manage PDF Forms with WPS Office
WPS Office provides a comprehensive and user-friendly PDF editor that allows you to easily create, fill, and manage interactive PDF forms without dealing with complicated configurations.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF Editor.
- 2. Navigate to the Form Tab: Click on the 'Form' tab on the top ribbon to access all interactive form creation tools.
- 3. Add or Edit Fields: Select 'Text Field' to draw new input areas, or double-click existing fields to modify their properties and formatting.

Frequently Asked Questions
Why does my PDF form display 'NaN' instead of a number?
'NaN' stands for 'Not a Number'. This usually happens when a calculation field tries to divide by zero because an input field is empty. You can resolve this by adding a custom calculation script that stops the calculation if the input fields are blank.
How do I fix number format errors in my PDF calculations?
Number format errors frequently occur if you use a comma (,) as a decimal separator in your scripts. Ensure you are using the English number format, which uses a period (.) as the decimal separator, inside any custom JavaScript code.
Can I hide the Pass/Fail field entirely until a calculation is made?
Yes. In the field properties, under the 'General' tab, you can set the field's 'Form Field' property to 'Hidden'. You can then use a custom script to change its visibility to 'Visible' only when the calculation conditions are met.




