PDF Editing Issues

How to Change Acrobat Form Text Color When a Specific Number is Entered

Algirdas JasaitisAlgirdas Jasaitis Nov 5, 2026 868 views

Question details

The user wants to automatically change the text color of multiple PDF form fields based on the entered numerical value using JavaScript.

How to Change Acrobat Form Text Color When a Specific Number is Entered
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.
Before you start

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.

Solution 1Recommended

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.

1
Open JavaScript Tools

In Adobe Acrobat, navigate to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.

2
Create the Function

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

3
Access Field Properties

Close the JavaScript window. Right-click the form field you want to modify, select 'Properties', and navigate to the 'Validate' tab.

4
Call the Function

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.

Use a Document-Level JavaScript Function to Format Text Color
JavaScript Syntax Check: JavaScript is case-sensitive. Ensure that your script perfectly matches the required casing, and remember that you can change the target value '5' to any specific number you need.
Powerful PDF Form Editor

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. 1. Open your PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form editing and filling options.
  3. 3. Modify Text Properties: Select the form fields to adjust their text color, font size, and alignment directly from the intuitive properties panel.
Easily fill, manage, and print interactive PDF formsHighly compatible with Adobe Acrobat PDF formatsEdit text, colors, and layouts directly within the PDF fileLightweight application with an intuitive, user-friendly interface
microsoft office alternative - wps office

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').