Change PDF Form Text and Fill Colors Based on a Drop-Down Selection
Question details
Change a PDF form field's text and fill colors according to a Pass or Fail drop-down selection.

- Product
- PDF forms
- Device & OS
- not provided
- Scenario
- A form designer wants a target field to display different colors when a user selects a result from a drop-down list.
- Observed behavior
- The desired result is white text on green for Pass, white text on red for Fail, and black text on white for other values.
Open the form in a PDF editor that supports Acrobat-compatible form JavaScript, such as Adobe Acrobat Pro. Identify the drop-down field, the target field name, and the drop-down export values.
Use a Drop-Down Validation Script in Adobe Acrobat Pro
Run a script when the drop-down value is committed to update the target field's colors.
This example uses a drop-down with export values Pass and Fail and a separate target field named Result. Change the field name and values in the script if your form uses different ones.
Open the PDF in Adobe Acrobat Pro and select Tools > Prepare a Form, or choose Prepare a form from the All tools menu.
Double-click the drop-down field, open the Options tab, and check that the Pass and Fail options have matching export values. Enable Commit selected value immediately so the script runs when a selection is made.
In the drop-down field properties, open the Validate tab, select Run custom validation script, and click Edit. Paste this script: var target = this.getField("Result"); if (target) { if (event.value === "Pass") { target.textColor = color.white; target.fillColor = color.green; } else if (event.value === "Fail") { target.textColor = color.white; target.fillColor = color.red; } else { target.textColor = color.black; target.fillColor = color.white; } }
Click OK to close the script editor and field properties, save the PDF, and leave form editing mode. Select Pass, Fail, and another available value in the drop-down to check the target field colors.

Work with PDFs and Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files, making it easy to move between formats. For the conditional PDF form script above, use an editor and viewer that support Acrobat-compatible JavaScript.

Frequently Asked Questions
Why don't the colors change when I select Pass or Fail?
In Prepare a Form, check the target field name and the drop-down option export values against the script. Also enable Commit selected value immediately on the drop-down's Options tab and test in a viewer that supports PDF form JavaScript.
Can the field show a default color for a blank selection?
Yes. The script's final else block sets black text and a white fill for any value other than Pass or Fail, including a blank value when that selection is committed.
Will the script work in every PDF viewer?
No. Some browser and mobile viewers do not support Acrobat-compatible form JavaScript. Open and test the saved PDF in the viewer intended for the form's users.
How do I use different field names or option values?
In the validation script, replace Result with the exact target field name and replace Pass and Fail with the corresponding drop-down export values. Check these in Prepare a Form field properties.




