Hide PDF Images and Radio Button States with Acrobat JavaScript
Question details
Control multiple PDF images with radio buttons and hide the images again when the document opens or the form resets.

- Product
- Adobe Acrobat and Acrobat Reader
- Device & OS
- not provided
- Scenario
- A PDF form uses radio buttons to display associated images.
- Observed behavior
- An image that was displayed remains visible after the page is refreshed or reopened, rather than returning to its hidden state.
Open the PDF in Adobe Acrobat and identify the radio group, its export values, and the image fields you want to control. Test the finished form in Acrobat or Reader, because browser PDF viewers may not run Acrobat JavaScript.
Control image button fields with Acrobat JavaScript
Use button fields as image containers and explicitly reset their visibility when the document opens or the form resets.
The example uses a radio group named ImageChoice with export values A and B, and button fields named ImageA and ImageB. Replace these names and values with those in your form.
In Acrobat, open Prepare a form and add a button field for each image. In each button's Properties, use the Options tab to choose an icon and an icon-only layout, then set the field to Hidden on the General tab.
In Prepare a form, add radio buttons in a group named ImageChoice. In each button's Properties, set its export value to match the image it should show, such as A or B.
Open Acrobat's Document JavaScripts tool and add a document-level script containing: function hideImages() { this.getField('ImageA').display = display.hidden; this.getField('ImageB').display = display.hidden; } hideImages();
In each radio button's Properties, open Actions and add a Run a JavaScript action for Mouse Up. Use: hideImages(); var choice = this.getField('ImageChoice').value; if (choice === 'A') this.getField('ImageA').display = display.visible; if (choice === 'B') this.getField('ImageB').display = display.visible;
If you have a reset button, use its Properties > Actions tab to run hideImages(); after its Reset a form action. Save the PDF, close and reopen it in Acrobat or Reader, then test each radio button and the reset button.

View PDFs and Work with Office Files in WPS Office
WPS Office is a free, lightweight alternative for viewing PDFs and working with Office files in a familiar interface. Its format compatibility makes it easy to move existing documents into your workflow. Use Acrobat to create and test the JavaScript-controlled PDF form described above.

Frequently Asked Questions
Why does the image remain visible after I reopen the PDF?
The field's visibility may not have been reset. Add a document-level script in Acrobat that sets each image field's display property to display.hidden when the document opens.
Can a browser PDF viewer run this script?
Browser support for Acrobat JavaScript varies, and some viewers do not run it. Open the saved PDF in Acrobat or Reader to test the form.
How do I hide all images when the form is reset?
In the reset button's Properties > Actions tab, add a Run a JavaScript action after Reset a form and call the function that sets the image fields to display.hidden.
Why does selecting a radio button not show the right image?
Check the radio buttons' export values in Properties and compare them with the values in the script. Also verify that the image button field names match the names passed to getField.




