Show a Custom Message When a PDF Form Field Contains 'Fail' Using JavaScript
Question details
The user needs to display a specific text message (e.g., "Report to SSM") in a target PDF form field whenever either of two other calculated fields contains the value "Fail".

- Product
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires conditional logic to trigger status warnings based on the results of other calculated fields.
- Observed behavior
- Requires a valid Acrobat JavaScript calculation utilizing the proper logical operator to evaluate multiple fields and output the desired string.
Ensure you are using a PDF editor with advanced form editing capabilities that supports custom JavaScript calculations, and verify the exact names of the form fields you want to evaluate.
Use a Custom JavaScript Calculation with the OR Operator
Apply a custom calculation script to the destination field using the JavaScript OR (||) operator to check the string values of the referenced fields.
To achieve conditional text output based on multiple fields, you need to use a ternary operator combined with the logical OR (`||`) operator. This ensures that if the first condition is met, it triggers the true state, and if not, it proceeds to check the second condition.
Open your PDF form in edit mode. Double-click the target text field (e.g., field 'A5') where you want the message to appear to open its Properties dialog.
In the Properties window, click on the 'Calculate' tab to set up the field's automated behavior.
Select the 'Custom calculation script' radio button, click 'Edit', and enter the following code: `event.value = this.getField("A2").valueAsString == "Fail" || this.getField("A4").valueAsString == "Fail" ? "Report to SSM" : "";`
Click 'OK' to close the JavaScript editor, then click 'Close' on the Properties dialog. Exit form editing mode to test your fields by triggering a 'Fail' state in either field A2 or A4.

Manage and Fill Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily view, fill, and manage interactive PDF forms while maintaining full compatibility with advanced scripts.
- 1. Open Your Form: Launch WPS Office and open your interactive PDF document.
- 2. Access Form Fill Mode: Navigate to the PDF viewer; WPS will automatically detect interactive fields and highlight them.
- 3. Input Data: Click into the fields to input your data. Calculated fields will update automatically based on their embedded scripts.
- 4. Save and Export: Once your form is completely filled out, click 'Save' or 'Export to PDF' to secure your entered data.

Frequently Asked Questions
Why is my PDF calculation script not updating the field?
This usually happens due to a typo in the field names or a syntax error in the JavaScript. Double-check that `this.getField("FieldName")` matches the exact capitalization of your form fields.
Can I check more than two fields for the 'Fail' condition?
Yes. You can chain additional conditions using the same OR (`||`) operator. For example: `... || this.getField("A6").valueAsString == "Fail"`.
Why use 'valueAsString' instead of just 'value'?
Using `valueAsString` strictly evaluates the field's content as a text string. This prevents unexpected JavaScript errors or type coercion issues when comparing the field's content against the text word 'Fail'.




