How to Change Acrobat Form Text Color When a Specific Number is Entered
Question details
The user wants to automatically change the text color of multiple PDF form fields based on the entered numerical value using JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms where text color highlights specific numerical inputs, such as changing the text color to red if the number 5 is entered, and returning to black for other values.
- Observed behavior
- The form fields need to dynamically update their text color upon validation of the user's input, requiring a reproducible script that can be applied to multiple fields.
Ensure you are using a PDF editor that fully supports document-level JavaScript execution, such as Adobe Acrobat Pro, and that your interactive form fields have already been created.
Use a Document-Level JavaScript Function to Format Text Color
Applying a document-level JavaScript function allows you to efficiently apply the same color-changing logic across multiple form fields without rewriting the code.
Instead of writing the same script for every single field, you can define a custom JavaScript function at the document level. This function evaluates the input value and applies the appropriate color change. Once created, it can be easily triggered from the validation tab of any form field.
In Adobe Acrobat, navigate to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.
Type a recognizable name for your script (e.g., 'ColorChange') and click 'Add'. Delete the default code and enter the following logic: function checkValue() { if (event.value == 5) { event.target.textColor = color.red; } else { event.target.textColor = color.black; } }.
Close the JavaScript window. Right-click the form field you want to modify, select 'Properties', and navigate to the 'Validate' tab.
Select 'Run custom validation script' and type checkValue(); in the text box. Click 'OK' and repeat this step for any other fields that require the same text color rule.

Edit and Fill PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to seamlessly edit text, fill out interactive PDF forms, and customize document properties without the need for complex programming.
- 1. Open your PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form editing and filling options.
- 3. Modify Text Properties: Select the form fields to adjust their text color, font size, and alignment directly from the intuitive properties panel.

Frequently Asked Questions
Why is the text color not changing when I enter the number?
The JavaScript may not be triggering correctly. Ensure that the custom script call is placed in the 'Validate' tab of the field properties, and verify that the JavaScript syntax is completely free of typographical errors.
Can I use a different color instead of red?
Yes, you can change 'color.red' in the JavaScript code to other supported Acrobat color arrays, such as 'color.blue', 'color.green', or you can define a custom RGB color.
Does this JavaScript function work on mobile PDF readers?
Most mobile PDF readers have limited or no support for Adobe Acrobat JavaScript. The dynamic text color change will function best when the document is opened in robust desktop PDF applications.
How do I apply this to a text string rather than a number?
To trigger the color change for a specific text string instead of a number, simply enclose the target value in quotation marks within the script, for example: if (event.value == 'TargetWord').




