Shoe/Hide layers Based on Radio Buttons

New Here ,
Mar 26, 2022 Mar 26, 2022

Copy link to clipboard

Copied

I have multiple layers and radio button in Acrobat form. 

Radio Buttons:

Group1 Yes, No

Group2 Yes, No

Group3 Yes, No

Group4 Yes, No

 

Layers:

Layer1

Layer2

Layer3

Layer4 

etc. 

All layers are hidden by default. I want Layer1 to show only when Yes is CHECKED. If No is checked the layer should be hidden. I want each group to work with each layer. 

If I use the default Javascript of show/hide layers, it works with all layers simultaneously. I want each layer connected with each radio button. 

Thanks for your help!

TOPICS
JavaScript , PDF forms

Views

168

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 26, 2022 Mar 26, 2022

Copy link to clipboard

Copied

What does you mean with default Javascript?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2022 Mar 26, 2022

Copy link to clipboard

Copied

Thanks for your reply!

If you go to the Properties of radio button and then Action Tab > Set Layer Visibility. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 26, 2022 Mar 26, 2022

Copy link to clipboard

Copied

When you want use a script use the action "Run a Javascript".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2022 Mar 26, 2022

Copy link to clipboard

Copied

Yes, but I cannot write the codes of javascript.  I have no knowledge of javascript. I need javascript for this and this is what I am looking for. 

Can you please write code for this?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Layers are called "data objects" in the parlance of Acrobat JS. To access one of them you can use the getDataObject method, specifying their name as the parameter, and then set the state property of that object to true or false to show or hide it (resp.).

 

Here's a simple example on how to show Layer1 and hide Layer2:

 

this.getDataObject("Layer1").state = true;

this.getDataObject("Layer2").state = false;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Thanks!

Based on your hint I tried this

if (event.target.value != "Off") {
// box is checked
this.getDataObject("Layer2.1").display = display.visible ;
} else {
// box is unchecked
this.getDataObject("Layer2.1").display = display.hidden ;
}

I added this in the Yes option(Mouse Up > Run a Javascript) but it didn't work. 

I wanted to show the layer if Yes is checked, If No is checked I don't want the layer to show. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Read my reply again. That is not how you show/hide layers.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

Sorry, I could not explain everything. I don't want to show one layer and hide other.

I want to show layer1 ONLY if  Yes is checked from Group1. 

I want to show layer2 ONLY if Yes is checked from Group2. 

I have attached an EXAMPLE form. 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 27, 2022 Mar 27, 2022

Copy link to clipboard

Copied

LATEST

I understood. I provided the sample code of how to generally show/hide a layer. You need to follow that example and adjust it to your specific needs.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines