Create a PASS or FAIL Button in Adobe Acrobat with JavaScript
Question details
Create a fillable PDF button that displays PASS or FAIL in a corresponding color based on a pressure-test field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A pipeline pressure-test form needs a large status button based on a numeric field value.
- Observed behavior
- The desired button displays PASS with a green background or FAIL with a red background after checking the test value.
Open the form in Acrobat and check the exact name of the field containing the numeric test value. Confirm the actual pass criteria for the pressure test; the example below uses a value greater than 5 only as an illustration.
Add a JavaScript Mouse Up action to the Acrobat form button
Use a button action to read the test value and update the button caption and background when the button is clicked.
Open the PDF in Adobe Acrobat, then choose All tools > Prepare a form. Select the existing form or create form fields if prompted.
Select the button tool in the form-editing toolbar and draw a button on the form. Open the button's Properties to set its initial caption and appearance.
In Button Properties, open the Actions tab. Set Select Trigger to Mouse Up and Select Action to Run a JavaScript, then click Add. Enter the following script, replacing FailPass with the exact source field name and 5 with the appropriate threshold: var raw = this.getField("FailPass").valueAsString; var value = Number(raw); if (raw.replace(/\s/g, "") === "" || !isFinite(value)) { event.target.buttonSetCaption("Enter value"); event.target.fillColor = color.ltGray; } else { var pass = value > 5; event.target.buttonSetCaption(pass ? "PASS" : "FAIL"); event.target.fillColor = pass ? color.green : color.red; }
Save the PDF, exit form editing, and enter test values in the source field. Click the button after each change to verify the PASS, FAIL, and empty-value states.

Work with PDF forms and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format support can make moving everyday files easier, but it does not replace Acrobat's JavaScript button-authoring workflow.

Frequently Asked Questions
How do I find the source field's name in Acrobat?
Choose All tools > Prepare a form, then open the source field's Properties. Check its name on the General tab and use that exact name in this.getField().
Can the button update automatically when the test value changes?
Yes, but that requires a different form-event setup. The Mouse Up action shown here updates the button only when it is clicked.
What happens if the test field is empty?
The example displays Enter value and changes the button background to light gray. It also uses that state when the entry cannot be converted to a number.
Why does the button work in Acrobat but not in another PDF viewer?
Some PDF viewers do not support Acrobat JavaScript or have it disabled. Test the saved form in a viewer that supports and allows Acrobat JavaScript.




