PDF Editing Issues

Change Text Color Based on Words in an Acrobat Form Field

John WilsonJohn Wilson Nov 19, 2026 869 views

Question details

Change an Acrobat form field's text color according to the word a user enters.

Change Text Color Based on Words in an Acrobat Form Field
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

Open the PDF in Acrobat and select All tools > Prepare a form. In some versions, select Tools > Prepare Form.

2
Open field properties

Double-click the target text field, or right-click it and select Properties.

3
Add the script

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;

4
Save and test

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.

Add a validation script to the Acrobat text field
Color applies to the whole field: The comparisons are case-sensitive and require an exact match. Detecting words within longer text needs different JavaScript; the textColor property still changes the entire field rather than coloring each word separately.
Free Microsoft Office alternative

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.

Open and view PDF forms alongside your other documentsCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for an easier transition from Microsoft OfficeFree to download and lightweight to use
microsoft office alternative - wps office

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.