How to Change PDF Text Field Colors Using Acrobat Radio Buttons
Question details
The user needs to automatically change the background colors of specific text fields depending on which radio button option is selected in a PDF form.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where selecting a 'Yes' or 'No' radio button triggers a color change (e.g., green or red) in corresponding text fields.
- Observed behavior
- The text fields require a JavaScript solution to dynamically update their fill color properties to either a specific color or transparent based on the active radio button's export value.
Verify that your PDF editor supports JavaScript execution for interactive forms. Make sure to note the exact field names and export values assigned to your radio button group before writing your scripts.
Use Custom Calculation Scripts on Text Fields
The most efficient method is to add a custom calculation script directly to the text fields, allowing them to automatically update their fill color when the radio button value changes.
By setting a calculation script on the target text fields, the fields constantly evaluate the current state of the radio button group and adjust their appearance accordingly. This ensures the background color is always synchronized with the user's selection.
Enter the form editing mode. Right-click the target text field (e.g., 'MDC_Yes') and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab in the Properties window and choose the 'Custom calculation script' option.
Click 'Edit' and enter the following script: event.target.fillColor = this.getField("MDC").valueAsString == "Yes" ? color.green : color.transparent;
Repeat the process for the second text field (e.g., 'MDC_No'). In its 'Calculate' tab, enter: event.target.fillColor = this.getField("MDC").valueAsString == "No" ? color.red : color.transparent;

Apply Action Scripts Directly to Radio Buttons
Alternatively, you can trigger a script whenever the radio button is clicked to push changes directly to the target text fields.
Create and Edit Interactive PDF Forms with WPS PDF
WPS Office features a comprehensive PDF editor that allows you to easily view, manage, and fill interactive PDF forms without the need for expensive dedicated software.
- 1. Open WPS Office: Launch WPS Office and click on the 'PDF' tab from the main dashboard.
- 2. Load Your PDF Form: Open your interactive PDF form document directly within the WPS PDF viewer.
- 3. Interact with Form Fields: Click on any form fields, checkboxes, or radio buttons to fill out your document seamlessly.
- 4. Save and Export: Once completed, simply save the document to preserve your inputs with full format compatibility.

Frequently Asked Questions
Why isn't my text field color updating when I select the radio button?
This usually happens if the radio button isn't committing its value immediately. To fix this, open the radio button properties, go to the 'Options' tab, and check the box for 'Commit selected value immediately'.
Can I use colors other than red, green, or transparent?
Yes, JavaScript in PDF forms supports various standard colors like color.blue, color.yellow, or color.black. You can also define custom RGB colors using an array format like ["RGB", 1, 0.5, 0].
How do I find the exact export value of my radio button?
Right-click the radio button, select 'Properties', and navigate to the 'Options' tab. Look for the 'Radio Button Choice' or 'Export Value' field. The text inside this box is the exact value you need to reference in your JavaScript.




