PDF Editing Issues

How to Change PDF Form Font Color Based on a Number

Chanuka GeekiyanageChanuka Geekiyanage Nov 5, 2026 869 views

Question details

The user wants to apply conditional formatting to a PDF form field so that the text color changes automatically depending on the numeric value entered (e.g., black for under 10, yellow for 10-19, red for 20 and above).

How to Change PDF Form Font Color Based on a Number
Product
PDF Editor
Device & OS
not provided
Scenario
Creating or modifying an interactive PDF form that requires visual cues based on specific numerical data ranges entered by respondents.
Observed behavior
The goal is to have the form field dynamically update its font color based on mathematical conditions applied to the user's input.
Before you start

Ensure you are using a PDF editor that supports custom JavaScript for form fields, and verify that the target field is set up to accept numeric data.

Solution 1Recommended

Use Custom JavaScript for Form Field Validation

Apply a custom JavaScript snippet to the PDF form field's properties to evaluate the entered number and change the text color accordingly.

By converting the field value to a number, you can use an if/else logic statement to test the value against your defined ranges. The script can be applied as a calculation, formatting, or validation script.

1
Open form field properties

Right-click on the specific text field in your PDF form and select 'Properties' from the context menu.

2
Navigate to the Format or Validate tab

Switch to the 'Format' or 'Validate' tab within the Properties dialog box.

3
Select custom script option

Choose 'Custom' or check the box for 'Run custom validation script' depending on which tab you are using.

4
Enter the JavaScript code

Input the following script: var n = Number(event.value); if (n <= 9) event.target.textColor = color.black; else if (n < 20) event.target.textColor = color.yellow; else event.target.textColor = color.red;

5
Save and test the form

Click 'OK' to save the script, close the properties window, and enter different numbers into the field to verify the text color changes correctly.

Use Custom JavaScript for Form Field Validation
Script Placement: Using this script in the 'Validate' tab ensures the color updates immediately after the user inputs the number and clicks outside the field.
Advanced PDF Editing

Easily Create and Edit Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive suite of PDF tools, allowing you to seamlessly view, edit, and manage fillable PDF forms without needing heavy or expensive software.

  1. 1. Open your PDF form: Launch WPS Office and open your interactive PDF document.
  2. 2. Access form editing tools: Navigate to the 'Form' tab on the top ribbon to view all form fields.
  3. 3. Modify field properties: Double-click any text field to access its properties, where you can adjust standard text colors, fonts, and appearance.
  4. 4. Save your document: Click the 'Save' icon or press Ctrl+S to preserve your updated PDF form settings.
Easily edit PDF text, images, and form fields in a user-friendly interface.Highly compatible with standard Adobe PDF interactive forms.Seamlessly open and edit Word, Excel, PowerPoint, and PDF files all in one app.Lightweight alternative that runs smoothly on Windows, Mac, and mobile devices.
microsoft office alternative - wps office

Frequently Asked Questions

Can I change a PDF form field color without using JavaScript?

You can change the default, static font color of a form field through its Appearance properties in any standard PDF editor. However, to dynamically change the color based on the value entered (conditional formatting), JavaScript is required.

Why is my PDF JavaScript color code not updating the text immediately?

If the color doesn't update until you click the field again, you may have placed the script in the 'Calculate' tab without a trigger. Placing the script in the 'Validate' or 'Format' tab ensures it executes as soon as the value is committed.

What standard color names can I use in PDF JavaScript?

Standard color arrays built into Acrobat JavaScript include color.black, color.white, color.red, color.green, color.blue, color.cyan, color.magenta, and color.yellow. For custom colors, you can use the syntax ['RGB', r, g, b].