Show and Hide PDF Layers with an Acrobat Drop-Down Menu
Question details
Use a PDF form drop-down to display the layer associated with the selected state and hide the other state layers.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A PDF contains state-specific layers and a form drop-down for selecting which state to display.
- Observed behavior
- The selected state's layer should be visible while the other state layers remain hidden.
Open the PDF in Acrobat Pro and check the exact state-layer names in the Layers panel. Make sure the drop-down options have distinct export values that you can map to those names.
Use drop-down validation JavaScript to control state layers
Use this method when the PDF already has separate layers for each state and you want a selection to show only its matching layer.
The script maps each drop-down export value to a layer name, hides the mapped state layers, and then shows the selected one. Replace the example values and layer names with the exact names in your PDF.
Form fields may not follow layer visibility in every PDF. Test them separately; you may need additional field visibility settings or JavaScript.
In Acrobat Pro, open All tools > Prepare a form. Select the drop-down field and open its Properties.
On the Options tab, add or check the state items and their export values. Enable Commit selected value immediately so the script runs when the selection changes.
On the Validate tab, select Run custom validation script and choose Edit. Enter the following script, replacing the example export values and layer names: var stateLayers = { "state_a": "State A", "state_b": "State B" }; var selectedLayer = stateLayers[event.value]; var ocgs = this.getOCGs(); if (ocgs) { for (var i = 0; i < ocgs.length; i++) { for (var value in stateLayers) { if (stateLayers.hasOwnProperty(value) && ocgs[i].name === stateLayers[value]) { ocgs[i].state = (ocgs[i].name === selectedLayer); break; } } } }
Close the field properties, exit form editing, and choose each item in the drop-down. Confirm that only the matching state layer appears and that any related form fields behave as intended.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move between files. It can help with everyday PDF viewing and editing, but it does not replace Acrobat's layer-control JavaScript setup.

Frequently Asked Questions
Where can I find the PDF layer names in Acrobat?
Open the Layers panel in Acrobat and note the exact names of the state layers. Use those names as the mapped values in the validation script.
Why does the layer not change until I leave the drop-down?
Open the drop-down field's Properties in Prepare a form, select the Options tab, and enable Commit selected value immediately.
What happens if a drop-down value is not mapped in the script?
The example script hides the mapped state layers without showing a replacement. Add the option's export value and its matching layer name to the stateLayers object.
Will form fields automatically hide with their PDF layer?
Not necessarily. Test each field after changing the drop-down selection; some fields may need separate visibility settings or JavaScript.
Will the drop-down work in every PDF viewer?
Not all PDF viewers support Acrobat JavaScript or optional content groups in the same way. Test the saved PDF in the viewer your audience will use.




