How to Loop Through Radio Button Widgets in Acrobat JavaScript
Question details
The user wants to inspect each widget in an Adobe Acrobat radio-button group using JavaScript to find which specific option is selected.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Developing or modifying an interactive PDF form with Acrobat JavaScript and needing to verify the status of individual radio buttons.
- Observed behavior
- The user needs a script to iterate over radio button widgets, or a more efficient method to extract the selected value from a radio group.
Before writing your JavaScript code, ensure that all radio buttons in your group share the exact same field name but have distinct export values configured in their properties.
Loop Through Widgets Using Acrobat JavaScript
Use a `for` loop to inspect each individual widget in the radio-button group by its index.
In Acrobat, multiple radio buttons that share a name are treated as a single field with multiple widget representations. You can determine the number of widgets by checking the length of the exportValues array and then loop through them.
Open your PDF form in Adobe Acrobat, enter Prepare Form mode, and open the JavaScript Console (Ctrl+J) or the calculation script window for your target field.
Get the radio-button group by defining a variable: `var f = this.getField("Group1");`
Count the number of available options in the group by checking the export values: `var n = f.exportValues.length;`
Write a `for` loop to iterate through each widget and check if it is selected using the `isBoxChecked()` method: `for (var i = 0; i < n; i++) { console.println(this.getField("Group1." + i).isBoxChecked()); }`

Get the Selected Radio Button Value Directly
If you only need to know which option is selected without inspecting every widget, you can directly query the group's value.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily design interactive forms, manage radio buttons, and fill out documents without relying on complex scripting.
- 1. Open your PDF Document: Launch WPS Office and open the PDF file you wish to make interactive.
- 2. Access the Form Tools: Navigate to the 'Form' tab located in the top ribbon menu.
- 3. Insert Form Fields: Select 'Radio Button' or other interactive fields to place them directly onto the document.
- 4. Save the Interactive Form: Configure your field properties and save the document. Your forms are fully compatible with other major PDF viewers.

Frequently Asked Questions
Why do my PDF radio buttons all get selected at once?
This happens if your radio buttons do not share the exact same 'Field Name' or if they have identical 'Export Values'. To behave as a mutually exclusive group, they must share a common name but feature distinct export values.
Can I use standard JavaScript arrays in Acrobat?
Yes, Acrobat JavaScript is based on Core JavaScript, so standard array methods work. However, Acrobat's DOM objects like `getField` return specific Field objects, requiring you to access properties like `exportValues.length` to iterate properly.
How do I clear the selection of a radio button group using JavaScript?
You can clear a radio button group by setting its value to 'Off' (with a capital O). For example: `this.getField("Group1").value = "Off";`
Is Acrobat JavaScript supported in all PDF viewers?
No, Acrobat JavaScript is fully supported in Adobe Acrobat, Adobe Reader, and robust editors like WPS PDF. Basic viewers, such as native browser PDF viewers, often cannot execute advanced JavaScript calculations or loops correctly.




