PDF Editing Issues

Show a Custom Message When a PDF Form Field Contains 'Fail' Using JavaScript

Phi Hung VoPhi Hung Vo Nov 5, 2026 869 views

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".

How to Display a Message When Any PDF Form Field Contains 'Fail'
Product
PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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.

2
Navigate to the Calculate Tab

In the Properties window, click on the 'Calculate' tab to set up the field's automated behavior.

3
Enter the Custom Script

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" : "";`

4
Save and Test

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.

Use a Custom JavaScript Calculation with the OR Operator
Field Name Accuracy: JavaScript is case-sensitive. Ensure that the field names referenced in the script (like "A2" and "A4") exactly match the actual names of the text fields in your PDF document.
Advanced PDF Editing

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. 1. Open Your Form: Launch WPS Office and open your interactive PDF document.
  2. 2. Access Form Fill Mode: Navigate to the PDF viewer; WPS will automatically detect interactive fields and highlight them.
  3. 3. Input Data: Click into the fields to input your data. Calculated fields will update automatically based on their embedded scripts.
  4. 4. Save and Export: Once your form is completely filled out, click 'Save' or 'Export to PDF' to secure your entered data.
Easily interact with and fill complex PDF forms containing calculated fields.Fully compatible with Microsoft Office formats (Word, Excel, PowerPoint) and standard PDF forms.Lightweight, fast, and features a user-friendly interface for seamless document management.
microsoft office alternative - wps office

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'.