How to Find Checkbox Widget Indexes with Acrobat JavaScript
Question details
The user needs to find the zero-based index of similarly named checkbox widgets (e.g., cb.0#0, cb.0#1) in a PDF form using Acrobat JavaScript to execute methods like isBoxChecked and checkThisBox.

- Product
- Device & OS
- not provided
- Scenario
- Writing JavaScript for an interactive PDF form to properly identify and interact with grouped checkbox widgets.
- Observed behavior
- To execute methods such as checkThisBox or isBoxChecked, the script requires the specific index of the checkbox widget, which is difficult to extract from similarly named fields.
Ensure you have a PDF editor that supports form field editing and JavaScript execution, and verify the exact names of your target checkbox fields before writing your scripts.
Determine the Index using the getArray() Method
This is the most reliable method, as it systematically checks the array of field objects to determine the exact position of the widget, regardless of selection status.
By retrieving all widgets associated with a specific field name, you can inspect their properties and identify their zero-based positions within the array.
Retrieve the targeted PDF field object by its common name within your JavaScript code.
Call the getArray() method on the field object to retrieve an array containing all similarly named widget objects.
Iterate through the returned array to inspect the widget objects and determine each widget's zero-based index based on its position.

Determine the Index using the exportValues Array
This is a quicker approach useful within an event script, provided that the checkboxes have unique export values and at least one checkbox is currently selected.
Edit PDF Forms and Checkboxes Easily with WPS Office
If you need a straightforward way to manage PDF forms, add checkboxes, and configure field properties without relying heavily on complex coding, WPS Office provides comprehensive PDF editing tools.
- 1. Open PDF File: Launch WPS Office and open your PDF document containing the forms.
- 2. Access Form Tools: Navigate to the 'Form' tab located on the top navigation ribbon.
- 3. Enable Form Editing: Click on 'Form Editing' to interact with existing fields, or select 'Check Box' to add new interactive widgets.
- 4. Modify Checkbox Properties: Right-click any checkbox and select 'Properties' to easily manage its group name, export values, and appearance.

Frequently Asked Questions
Why do multiple PDF checkboxes have the same name?
In PDF forms, checkboxes sharing the same name are treated as a logical group, similar to radio buttons. This allows form designers to group related options. They are differentiated internally by their unique export values and their zero-based widget index.
What happens if export values are not unique in my checkbox group?
If export values are identical for checkboxes sharing the same name, selecting one checkbox will automatically select all other checkboxes in that group. To function independently while sharing a name, each widget must have a unique export value.
Can I use the export-values method when no checkbox is checked?
No, the export-value approach only works when a checkbox is currently selected, as it relies on matching the active value. If no checkboxes are selected, you must use the getArray() method to identify the widget index.




