How to Show and Hide Radio Button Groups using JavaScript in Adobe Acrobat
Question details
The user wants to dynamically control the visibility of a radio button group in a PDF form using JavaScript based on a dropdown selection.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where certain fields (like radio buttons) only appear when specific conditions in a dropdown menu are met.
- Observed behavior
- Needs the exact JavaScript syntax and method to toggle the display property of a grouped radio button field.
Ensure you have Adobe Acrobat Pro installed, as the standard version or the free Adobe Reader does not support editing PDF forms or adding custom JavaScript.
Toggle Radio Button Group Visibility with JavaScript
Use Acrobat's built-in JavaScript editor to conditionally change the display property of grouped radio buttons.
To manage radio buttons effectively in Acrobat JavaScript, all buttons in the same group must share the exact same field name. You can then target this single group name to hide or show all associated buttons at once.
Open your PDF form in Adobe Acrobat Pro and select the 'Prepare Form' tool from the right-hand pane.
Ensure all radio buttons in your target group share the exact same 'Name' in their Properties (e.g., 'group1'). You can check this by right-clicking each radio button and selecting 'Properties'.
Right-click the dropdown field that will trigger the visibility change, select 'Properties', and navigate to the 'Format' or 'Calculate' tab to add a custom script.
Enter the JavaScript code: `if (event.value == 'TargetValue') { this.getField('group1').display = display.visible; } else { this.getField('group1').display = display.hidden; }`. Replace 'TargetValue' with your actual dropdown selection.
Click 'OK', close the Properties dialog, and click the 'Preview' button at the top right to test your form and ensure the radio buttons hide and show correctly.

Edit PDFs and Documents with WPS Office
While Adobe Acrobat is required for complex JavaScript form programming, WPS Office provides a comprehensive, lightweight, and free alternative for your daily document and PDF editing needs. It seamlessly integrates Word, Excel, PowerPoint, and powerful PDF tools into one familiar interface, making document management incredibly simple.
- 1. Download the software: Download and install WPS Office for free from the official website.
- 2. Open your PDF: Launch WPS Office and click on 'PDF Edit' or simply drag and drop your PDF document into the workspace.
- 3. Edit and save: Use the extensive top-menu tools to edit text, fill forms, merge pages, or effortlessly convert your PDF to Word formats.

Frequently Asked Questions
Why is this.getField('group1') returning null in my Acrobat script?
This usually happens if the field name is misspelled in your script or if the field does not exist. Double-check that your radio buttons are named exactly 'group1' (case-sensitive) in their properties.
Can I hide individual radio buttons instead of the whole group?
Yes, but you must reference the specific widget index of the radio button. However, it is generally best practice to group them under one name and toggle the visibility of the entire group for simplicity.
Do these JavaScript actions work in Adobe Acrobat Reader?
Yes, once the scripts are added to a PDF form using Acrobat Pro and the file is saved properly, the JavaScript will execute correctly in the free Adobe Acrobat Reader when end-users fill out the form.
How do I hide text fields along with the radio buttons?
You can duplicate the display toggle line in your JavaScript and target the text field's name as well. For example: `this.getField('TextField1').display = display.hidden;`.




