• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Drop down menu shows layer, hides the rest (newbie)

Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

I have 30 layers that I created in InDesign and exported to PDF (multiple pages). I created a dropdown menu with corresponding item lists. I want to be able to show only the layer selected from the dropdown list (plus keep the main header layer active at all times). I found this post that almost worked for me, but it kept previously selected layers active once I changed the selection. I need the the other layers to hide if the selection changes. Thank you for your time, and please take it easy on me, this is my first attempt at Javascript!

TOPICS
Acrobat SDK and JavaScript

Views

825

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

correct answers 1 Correct answer

Community Expert , Mar 07, 2019 Mar 07, 2019

That code should have worked in your case... Try this version of it, instead:

 

var ocgs = this.getOCGs();
if (ocgs) {
    for (var i in ocgs) {
        ocgs[i].state = (ocgs[i].name==event.value);
    }
}

 

Place this code as the custom validation script of the drop-down field and make sure to tick the option to commit the selected value immediately (under the Options tab).

 

[Edited: Code fixed]

Votes

Translate

Translate
Community Expert ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

That code should have worked in your case... Try this version of it, instead:

 

var ocgs = this.getOCGs();
if (ocgs) {
    for (var i in ocgs) {
        ocgs[i].state = (ocgs[i].name==event.value);
    }
}

 

Place this code as the custom validation script of the drop-down field and make sure to tick the option to commit the selected value immediately (under the Options tab).

 

[Edited: Code fixed]

Votes

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
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Thank you! Is there any way to make one of the 30 layers stay visible at all times?

Votes

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
Community Expert ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Sure. You can add something like this before line #4 above:

if (ocgs[i].name=="Layer0") continue;

Votes

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
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

You have just remedied hours of searching and trial/error on my end. Much appreciated.

Votes

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 ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Just to confirm, with this code, when I select an item in my drop-down list, it can pull-up the info/image I have on a specific layer, right? If so, within this code, where do the names of the items in your drop-down list go, and where do the names of the layers go? I need to make the same thing happen, but don't know anything about JavaScript. TIA!

Votes

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
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

They don't go anywhere. The code above assumes the items in the drop-down match the names of the layers.

If that's not the case, the code will have to be adjusted accordingly.

Votes

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 ,
Aug 01, 2024 Aug 01, 2024

Copy link to clipboard

Copied

Thx! That should have made it easier, but I still can't get it to work. My drop-down item and layer names are the same and I've selected "commit the selected value immediately". I copied and pasted the code into the Validate Tab, under "Run custom validation script". Are there any other sections in the Properties Menu that need to be updated to make this code work? I'm working with Acrobat Pro 2017, just in case that's relevent. TIA!

Votes

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
Community Expert ,
Aug 01, 2024 Aug 01, 2024

Copy link to clipboard

Copied

No, that should be enough. Can you share the file?

Votes

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 ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Thanks again for your help! I can't share the actual file, but here's a quick example of what I'm doing in my document. Please let me know if you can figure out what I'm doing wrong 🙂 

Votes

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
Community Expert ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

Sorry, my bad. There was an error in the code I posted earlier. I fixed it now. Copy it again and try again.

Votes

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 ,
Aug 02, 2024 Aug 02, 2024

Copy link to clipboard

Copied

LATEST

That's it! It works great 🙂 Thanks so much for the quick responses, it's good to know the community has such great support.

Votes

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