PDF Editing Issues

How to Use JavaScript for Automatic Pass or Fail Results in Acrobat PDF Forms

Muhammad TalhaMuhammad Talha Nov 3, 2026 869 views

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.

How to Use JavaScript for Automatic Pass or Fail Results in PDF Forms
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.
Before you start

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.

Solution 1Recommended

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.

1
Access Field Properties

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.

2
Navigate to Custom Calculations

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.

3
Insert the JavaScript Code

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"; }

4
Save and Test the Script

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.

Apply a Custom Calculation JavaScript to the Result Field
Script Explanation: The script converts the input strings to numbers. If the primary field is 0 or completely empty, the result field remains blank. Otherwise, it compares the values mathematically to determine the Pass or Fail status.
Powerful PDF Form Support

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. 1. Open the PDF Form: Launch WPS Office and open your interactive PDF document containing the calculation scripts.
  2. 2. Input the Data: Click into the designated input fields and enter your numeric values.
  3. 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.
Fully compatible with interactive PDF form fields and standard embedded scriptsAutomatically executes built-in PDF calculations for quick data entryFree, lightweight, and user-friendly PDF reader and editor
microsoft office alternative - wps office

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.