Change Text Color Based on Words in an Acrobat Form Field
Question details
Change an Acrobat form field's text color according to the word a user enters.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form should display “due” in red and “c/w” in green when either is entered in a text field.
- Observed behavior
- The field text should change color based on its value, with other values displayed in black.
Open the PDF in Adobe Acrobat and confirm that the target is an editable form text field, not a text box annotation. You need access to the field's properties and JavaScript validation settings.
Add a validation script to the Acrobat text field
Use this method when the field contains one exact value at a time, such as “due” or “c/w”.
The script changes the color of the entire field, not individual words within a longer entry. It runs when the field value is validated, typically after the user leaves the field.
Open the PDF in Acrobat and select All tools > Prepare a form. In some versions, select Tools > Prepare Form.
Double-click the target text field, or right-click it and select Properties.
On the Validate tab, select Run custom validation script and click Edit. Enter: if (event.value == "due") event.target.textColor = color.red; else if (event.value == "c/w") event.target.textColor = color.green; else event.target.textColor = color.black;
Click OK to close the script editor, close the field properties, and save the PDF. Leave form-editing mode, enter “due” or “c/w”, and move out of the field to check the color.

View PDFs and work with Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for viewing PDFs and working with Office files. Its format compatibility makes it easy to bring existing documents into your workflow, although it does not configure Acrobat form validation scripts.

Frequently Asked Questions
Why does the color change only after I leave the field?
A custom validation script runs when Acrobat validates the field value, typically when you move focus to another field. Click outside the field after entering the value to test it.
Will the script recognize “Due” or extra spaces?
No. The example uses case-sensitive exact comparisons, so “Due” and “due ” fall through to black. Adjust the script to normalize the value if those variations should match.
Can this script color two different words inside the same field?
No. The field's textColor property changes all of its text to one color. A script can detect words within longer text, but this property alone cannot give each word a different color.
Will the color script work in every PDF viewer?
Not necessarily. PDF viewers differ in their support for Acrobat JavaScript and form validation. Test the saved form in the viewer your recipients will use, with JavaScript enabled where applicable.




