PDF Editing Issues

How to Conditionally Underline a PDF Text Field Using a Radio Button

Adam DavisAdam Davis Nov 5, 2026 869 views

Question details

The user needs to conditionally underline text in a PDF form field when a specific 'Yes' radio button is selected, but their current JavaScript implementation is not working.

How to Conditionally Underline a PDF Text Field with a Yes/No Radio Button
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form that automatically updates the text formatting of a field based on a user's radio button selection.
Observed behavior
The current script utilizing rich-text formatting fails to underline the text field when the radio button state changes.
Before you start

Ensure you are using a professional PDF editor with form creation and JavaScript capabilities, and verify that the target text field has 'Allow Rich Text Formatting' explicitly enabled in its properties.

Solution 1Recommended

Configure JavaScript on the Radio Button Action

Trigger the rich-text formatting update directly when the user clicks the Yes or No radio button.

For JavaScript to dynamically change text formatting in a PDF, the target text field must be configured to accept rich text. You can then attach an action script to the radio button that modifies the richValue spans of the text field.

1
Enable Rich Text Formatting

Right-click the target text field, select 'Properties', navigate to the 'Options' tab, and check the box for 'Allow Rich Text Formatting'.

2
Access Radio Button Actions

Right-click the Yes/No radio button, choose 'Properties', and navigate to the 'Actions' tab.

3
Set Up the Trigger

Select 'Mouse Up' from the 'Select Trigger' dropdown, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.

4
Enter the JavaScript Code

Input a script that checks the value of the radio button. If the value is 'Yes', use the script to set the target field's richValue array with {textDecoration: 'underline'}. Ensure you include an 'else' statement to restore the normal formatting if 'No' is selected.

Configure JavaScript on the Radio Button Action
Script Placement: Placing the script on the radio button's 'Mouse Up' event ensures the formatting updates instantaneously when the user makes a selection.
Powerful PDF Editor

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides comprehensive PDF editing tools, allowing you to easily create forms, add interactive fields, and manage properties without dealing with complex coding. Fully compatible with standard PDF formats.

  1. 1. Open PDF File: Launch WPS Office and open your PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon to access interactive elements.
  3. 3. Insert Form Fields: Use the 'Text Field' and 'Radio Button' tools to insert interactive elements onto your page.
  4. 4. Adjust Properties: Double-click the inserted fields to adjust properties like text formatting, field names, and export values.
Easily insert and customize radio buttons, checkboxes, and text fieldsFully compatible with standard Adobe PDF forms and JavaScript formattingLightweight, fast, and user-friendly interface for effortless navigationRobust set of free basic tools for seamless document management
QA img-9

Frequently Asked Questions

Why isn't my PDF JavaScript applying the underline formatting?

For rich-text scripts to work in a PDF text field, you must explicitly check the 'Allow Rich Text Formatting' option located in the text field's 'Options' tab. Without this enabled, scripts modifying richValue arrays will be ignored.

Can I apply other text formats conditionally using JavaScript?

Yes. By modifying the richValue object in your JavaScript, you can dynamically change font color, font weight (bold), italic styling, and text size based on user interactions.

How do I remove the underline if the user changes their selection to 'No'?

Your JavaScript logic must include an 'else' block. If the 'Yes' condition sets the textDecoration property to 'underline', the 'else' condition should set it to 'none' to revert the formatting when 'No' is clicked.