How to Use JavaScript for Automatic Pass or Fail Results in Acrobat PDF Forms
Question details
The user needs to set up a custom calculation script in a PDF form to compare two fields and output a Pass, Fail, or blank result automatically.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or editing interactive PDF forms with automated conditional calculations.
- Observed behavior
- The target form field needs to automatically display 'Pass', 'Fail', or remain blank based on the numeric values entered into two specific input fields.
Ensure you know the exact internal field names of the two fields you intend to compare, as you will need to reference them directly in your JavaScript code.
Apply a Custom Calculation JavaScript to the Result Field
Use Acrobat's custom calculation script feature to evaluate the input values and return a conditional string result.
By using the custom calculation script option in the field properties, you can write conditional statements (If/Else) to compare input fields and output specific text labels.
Enter 'Prepare Form' mode. Right-click the text field where you want the Pass or Fail result to appear, and select 'Properties' from the context menu.
Click on the 'Calculate' tab at the top of the Properties dialog box. Select the 'Custom calculation script' radio button, then click the 'Edit' button.
Type the following code into the JavaScript editor. Be sure to replace 'Text320' and 'Text341' with your actual field names: var v1 = Number(this.getField("Text320").valueAsString); var v2 = Number(this.getField("Text341").valueAsString); if (v1 == 0) { event.value = ""; } else if (v1 > v2) { event.value = "Fail"; } else { event.value = "Pass"; }
Click 'OK' to close the JavaScript editor, then close the Properties dialog box. Switch to the Hand tool or 'Preview' mode to enter numbers into the fields and verify the calculation updates correctly.

Fill and Manage Interactive PDF Forms with WPS Office
After configuring complex JavaScript calculations in your authoring tool, you can seamlessly open, fill, and process these interactive PDF forms using WPS PDF. It perfectly handles embedded scripts and form logic.
- 1. Open the PDF Form: Launch WPS Office and open your interactive PDF document containing the calculation scripts.
- 2. Input the Data: Click into the designated input fields and enter your numeric values.
- 3. View Automated Results: Navigate to the next field or click away; the embedded Pass/Fail calculation will automatically trigger and display the correct result.

Frequently Asked Questions
Why does my result field show an error when the input fields are blank?
If your fields are blank, the script might attempt to evaluate empty strings without converting them properly. Using the 'Number()' function and 'valueAsString' in the provided script ensures blank fields are safely treated as 0.
Do I need to learn advanced JavaScript to create basic PDF forms?
No. Standard calculations like Sum, Average, or Product are built directly into PDF field properties. However, customized conditional logic like Pass/Fail strings require simple JavaScript.
Can I use text values instead of numbers for the Pass/Fail condition?
Yes, but you will need to modify the script to remove the 'Number()' conversion. You can then compare the string values directly using standard JavaScript string comparison operators.




