How to Use PDF JavaScript to Set Approved Status with Radio Buttons
Question details
The user needs to capture the value of a selected radio button in an interactive PDF form using JavaScript to set a variable for email processing and properly validate required radio buttons.

- Product
- PDF Form
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a supervisor selects an 'Approved' or 'Disapproved' radio button, which dynamically updates a variable used for an email subject and body.
- Observed behavior
- The user requires the correct JavaScript logic to retrieve the radio button's state and correctly validate required fields, specifically handling the default 'Off' value of unselected radio buttons.
Ensure your PDF editor supports JavaScript for form fields, and verify that your mutually exclusive radio buttons share the exact same field name before applying the script.
Use JavaScript to Read Radio Button Values
Extract the value from the radio button group and assign it to an approval variable for email processing.
To properly read a radio button selection, you can check the value of the radio group. If the group shares a single name, it acts as one field. Depending on which button is selected, it returns that specific button's export value.
Open your interactive PDF form in edit mode and right-click the button or field that will trigger the email script. Select 'Properties'.
Navigate to the 'Actions' tab, select 'Run a JavaScript' from the action list, and click 'Add'.
In the JavaScript editor, input the following logic to check the radio button (assuming the field name is 'Radio'): if (this.getField("Radio").value == "Yes") { S_auth = "Approved"; } else { S_auth = "Disapproved"; }
Use the newly populated S_auth variable to build your email subject and body string before passing it to the mail submission function.

Validate Required Radio Button Fields
Check if a user has failed to select an option by looking for the default 'Off' value.
Manage and Edit PDF Forms with WPS Office
WPS PDF provides robust, easy-to-use tools to create interactive PDF forms, insert radio buttons, text fields, and manage form properties seamlessly. You can easily build professional documents and collect responses.
- 1. Open your PDF Document: Launch WPS Office and open your PDF file using the WPS PDF editor.
- 2. Navigate to Form Tools: Click on the 'Form' tab in the top ribbon to access the interactive form creation tools.
- 3. Insert Radio Buttons: Select the 'Radio Button' icon and click on the document page to place mutually exclusive options.
- 4. Configure Properties: Double-click the inserted radio button to configure its name, export values, and required status.

Frequently Asked Questions
Why does my required radio button validation fail?
When validating radio buttons in PDF JavaScript, an unselected radio button group returns the string value 'Off'. Ensure your script checks for f.value == 'Off' rather than an empty string.
Can I use the radio button value directly in an email subject?
Yes. Once you assign the radio button's value to a variable based on the selection, you can concatenate this variable into a mailto link or use it in an email submission script string.
Are mutually exclusive radio buttons treated as one field?
Yes, mutually exclusive radio buttons must share the exact same field name but have different export values (e.g., 'Yes' and 'No'). The JavaScript getField method references the group as a single entity.




