How to Add Acrobat JavaScript Pass or Fail Calculation to a PDF Form
Question details
The user needs a custom JavaScript calculation for a PDF form to automatically display 'Pass' or 'Fail' based on the numerical value entered in another specific field.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Evaluating input data in a PDF form to automatically generate a Pass/Fail status without manual data entry.
- Observed behavior
- A target field needs to display 'Fail' if the input value exceeds 0.5, and 'Pass' if the value is 0.5 or lower.
Ensure your PDF editor supports advanced form field properties and custom JavaScript calculations. Verify the exact field names you plan to reference in your script, as JavaScript is strictly case-sensitive.
Apply a Custom Calculation Script to the Form Field
Use JavaScript within the field properties to evaluate the value of the source field and output 'Pass' or 'Fail' accordingly.
PDF forms can utilize JavaScript to perform conditional logic automatically. By attaching a custom calculation script to your target text field, it will constantly monitor the value of your input field and update its own text output based on the parameters you set.
Open your PDF document in Edit Form mode and double-click the target field (e.g., 'PassFailRow1') to open its Properties dialog.
Navigate to the 'Calculate' tab at the top of the Properties window and select the 'Custom calculation script' option.
Click the 'Edit' button and paste the following JavaScript code: if (this.getField("Drop gaugeRow1").value > 0.5) { event.value = "Fail"; } else if (this.getField("Drop gaugeRow1").value <= 0.5) { event.value = "Pass"; } else { event.value = ""; }
Ensure you replace 'Drop gaugeRow1' with the exact name of your source data field. Click 'OK', close the properties window, and enter test values into the source field to verify the calculation.
Manage and Fill Advanced PDF Forms with WPS Office
WPS Office provides powerful PDF reading and editing tools, allowing you to easily view, fill, and manage interactive PDF forms that contain complex JavaScript calculations.
- 1. Open WPS PDF: Launch WPS Office and open your interactive PDF document using the built-in PDF reader.
- 2. Access Form Fields: Click directly on the interactive form fields to enter your data. WPS PDF automatically processes standard embedded calculation scripts.
- 3. View Calculated Results: Input your numerical values into the gauge field and watch the target field automatically update to 'Fail' or 'Pass' based on the document's logic.
- 4. Save Your Data: Once the form is filled, click 'Save' or press 'Ctrl+S' to keep your completed form and calculated results securely saved.

Frequently Asked Questions
Why isn't my JavaScript calculation updating automatically when I enter a value?
The calculation sequence might be incorrect, or the source field may not be set to commit its value immediately. Check the source field's properties under the 'Options' tab and ensure 'Commit selected value immediately' is checked.
Can I hide the Pass/Fail text if the source field is left empty?
Yes. While a blank field often defaults to 0 numerically, you can prevent it from displaying 'Pass' by adding an initial check in your script: if (this.getField("Drop gaugeRow1").valueAsString === "") { event.value = ""; } else if (...) { ... }.
How do I change the text color to red for Fail and green for Pass?
You can dynamically modify the text color by adding event.textColor = color.red; inside the Fail condition block, and event.textColor = color.green; inside the Pass condition block of your JavaScript.
Are PDF form calculations supported on mobile devices?
Support for custom JavaScript calculations in PDF forms varies widely on mobile devices. While desktop applications like Acrobat and WPS Office handle them perfectly, many basic mobile PDF viewers do not execute JavaScript. It is recommended to use a robust PDF app if filling forms on mobile.




