How to Use JavaScript to Change Tab Focus with Radio Buttons in PDF Forms
Question details
The user needs to dynamically move the form field focus to different text fields depending on whether a Yes or No radio button is selected.

- Product
- PDF Form Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where navigation and focus adapt automatically based on the user's radio button selections.
- Observed behavior
- The cursor focus needs to jump to specific form fields immediately after a user clicks a radio button, requiring custom JavaScript.
Ensure your PDF form fields are fully created and correctly named before adding JavaScript, as the script relies on exact field names to set the focus correctly.
Use a Mouse Up JavaScript Action on Radio Buttons
Apply a custom JavaScript snippet to the 'Mouse Up' action of the radio buttons to dynamically shift focus based on their export values.
This method uses conditional JavaScript statements to check the export value of the clicked radio button. If 'Yes' is selected, it routes the cursor focus to one specific field, and if 'No' is selected, it routes focus to another. It ensures a seamless fill-out experience for the end-user.
Open your PDF in form editing mode, select all the applicable radio buttons you want to trigger the script, right-click them, and choose 'Properties'.
Navigate to the 'Actions' tab in the Properties window. Select 'Mouse Up' as the trigger behavior and choose 'Run a JavaScript' from the Select Action drop-down menu.
Click 'Add' and paste the following script: if (event.target.value != 'Off') { if (event.target.value == 'Yes') { this.getField('FIELD1').setFocus(); } else if (event.target.value == 'No') { this.getField('FIELD2').setFocus(); } }
Replace 'FIELD1' and 'FIELD2' in the script with the exact actual names of your destination text fields. Confirm that your radio buttons' export values are accurately set to 'Yes' and 'No', then close the window and save the form.

Create and Fill Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to easily edit, fill, and manage interactive PDF forms. It is lightweight, fully compatible with standard PDF formats, and offers an intuitive interface without a steep learning curve.
- 1. Open WPS PDF: Launch WPS Office and open your interactive PDF form using the WPS PDF tool.
- 2. Navigate to the Form Tab: Click on the 'Form' tab in the top ribbon to access available form editing and filling tools.
- 3. Interact with Form Fields: Click on the radio buttons, text boxes, or dropdowns to fill out the document seamlessly. Focus shifts naturally as you navigate.
- 4. Save and Export: Once your form is filled, click 'Save' or export it directly to ensure all your selections and data are permanently recorded.

Frequently Asked Questions
Why isn't the tab focus shifting when I click the radio button?
This usually happens if the target field names in your JavaScript do not exactly match the actual field names in your form, or if the export values of the radio buttons are not set to 'Yes' and 'No'. Double-check for typos and verify case sensitivity.
Can I use this JavaScript logic for checkboxes instead of radio buttons?
Yes, but you will need to modify the script to check the specific export value or the 'isBoxChecked' status of the checkbox rather than checking 'event.target.value' as you would with grouped radio buttons.
How do I find the exact name of a form field to use in the script?
In form editing mode, double-click or right-click the target field and select 'Properties'. The exact, case-sensitive name of the field will be displayed in the 'General' tab.
Will this JavaScript focus script work on mobile PDF readers?
JavaScript support varies heavily across mobile PDF readers. While it works perfectly in desktop software like Adobe Acrobat or dedicated PDF editors, many mobile apps may ignore custom JavaScript actions, so the focus might not shift automatically on smartphones.




