PDF Editing Issues

Change PDF Form Field Color Based on Text Input

Anum MushtaqAnum Mushtaq Oct 28, 2026 869 views

Question details

The user needs to dynamically change the color of a specific PDF form field depending on whether multiple designated text fields are filled or empty.

Change a PDF Form Field Color Based on Text Input
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form that provides visual feedback (like red or green indicators) based on the completion status of required text fields.
Observed behavior
A target field needs to turn green when the 'morning', 'afternoon', and 'evening' fields all contain text, and turn red if any of these fields are left empty.
Before you start

Ensure you have access to a PDF editor that supports JavaScript custom calculations, and verify the exact names of the text fields you intend to monitor (e.g., 'am', 'pm', 'eve').

Solution 1Recommended

Use a Custom Calculation Script for Fill Color

Apply a JavaScript calculation to update the field's background color dynamically based on the input values of referenced fields.

By adding a custom calculation script to the target field, you can continuously monitor the status of the 'am', 'pm', and 'eve' text fields and update the background color accordingly.

1
Open Field Properties

Open your PDF in form editing mode, right-click the field whose color should change, and select 'Properties' from the context menu.

2
Navigate to Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab and choose the 'Custom calculation script' option.

3
Enter the JavaScript Code

Click the 'Edit' button and enter the following script: event.target.fillColor = (this.getField('am').valueAsString != '' && this.getField('pm').valueAsString != '' && this.getField('eve').valueAsString != '') ? color.green : color.red;

4
Save and Test

Click 'OK' to save the script, close the properties window, and fill out the form fields to verify the target field's background color turns green or red as expected.

Use a Custom Calculation Script for Fill Color
Field Renaming for Copies: If you need to apply this to multiple groups, use the 'Create Multiple Copies' feature so each group of fields references its own unique field names efficiently.
Advanced PDF Tools

Create and Customize Interactive PDF Forms with WPS Office

WPS Office offers a comprehensive suite of PDF tools, making it easy to create fillable forms, adjust field properties, and manage interactive document components without hassle.

  1. 1. Open PDF File: Launch WPS Office and open your PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab located on the top ribbon.
  3. 3. Insert or Edit Fields: Click 'Text Field' to insert new fields, or double-click existing fields to open their configuration menus.
  4. 4. Adjust Properties: Modify appearance, format, and calculation settings within the field properties dialog.
  5. 5. Save the Document: Save your interactive PDF document to lock in the form behaviors.
Easily add, delete, and customize PDF text fields with built-in form builders.Highly compatible with Adobe Acrobat and Microsoft Office PDF formatting standards.Intuitive form editing interface for faster document preparation and review.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my form field color updating automatically?

Ensure that JavaScript is enabled in your PDF viewer's preferences. Also, verify that the field names referenced in your custom script exactly match the actual field names assigned to your text boxes, as they are case-sensitive.

Can I apply this color change to multiple groups of fields on the same page?

Yes. After applying the script, you can copy the field group. However, you must rename the copies or use the 'Create Multiple Copies' feature to ensure each new group references its own unique field names rather than the original ones.

Why does changing the stroke color not show any visible change on the form?

If you are using a script to change the 'strokeColor' (border color), the target field's border width must be set to greater than zero in its Appearance properties. If the width is set to zero, the border remains invisible regardless of the assigned color.