PDF Editing Issues

Create a PASS or FAIL Button in Adobe Acrobat with JavaScript

Algirdas JasaitisAlgirdas Jasaitis Nov 18, 2026 869 views

Question details

Create a fillable PDF button that displays PASS or FAIL in a corresponding color based on a pressure-test field.

Create a PASS or FAIL Button in Adobe Acrobat with JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

Open the PDF in Adobe Acrobat, then choose All tools > Prepare a form. Select the existing form or create form fields if prompted.

2
Add a large button

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.

3
Add the JavaScript action

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

4
Save and test the form

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.

Add a JavaScript Mouse Up action to the Acrobat form button
Button updates on click: The Mouse Up action runs when the user clicks the button, not automatically when the source field changes. The PDF viewer must support and allow Acrobat JavaScript.
Free Microsoft Office alternative

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.

Open and review PDF forms alongside other documentsCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar office-style interface for everyday document workFree, lightweight option for working across common file types
microsoft office alternative - wps office

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.