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

Resetting layers

Community Beginner ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Hi,

I'm trying to setup a button to turn off 9 layers on an interactive pdf form.

8 out of 9 of the layers turn off no problem but the 1 layer remains turned on. Really not sure why this is happening. Double checked obvious things like layer names but to no avail. The WR1 layer will not turn off when I click the reset button.

Could anyone please help me with this 'simple' task as I am not particularly advanced with Javascript.

PDF form attached here https://we.tl/t-gS6R4unxWl

Thanks in advance.

var layer = this.getOCGs();

for(var i=0; i<layer.length; i++)

{

if(event.target.value=="Yes")

{

if(layer.name=="WR1")

{layer.state=false};

}

{

if(layer.name=="CL1")

{layer.state=false};

}

{

if(layer.name=="NC1")

{layer.state=false};

}

{

if(layer.name=="WR2")

{layer.state=false};

}

{

if(layer.name=="CL2")

{layer.state=false};

}

{

if(layer.name=="NC2")

{layer.state=false};

}

{

if(layer.name=="WR3")

{layer.state=false};

}

{

if(layer.name=="CL3")

{layer.state=false};

}

{

if(layer.name=="NC3")

{layer.state=false};

}

}

Message was edited by: Ross Jackson

TOPICS
Acrobat SDK and JavaScript , Windows

Views

601

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 , Jan 04, 2019 Jan 04, 2019

That's because this field is not a check-box, but a button, so it doesn't have any value.

Remove the first and last lines of the code and try again.

Votes

Translate

Translate
Community Expert ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Where is the reset button?

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Screenshot 2019-01-04 at 12.36.39.png

Ideally I would like the layers to toggle on/off with the 3 small buttons above each logo but also act like radio buttons so you can only choose one at a time.

Thanks for your help.

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Your code is not set up correctly. This line only applies to the first layer:

if (event.target.value=="Yes") 

I recommend you use indentation to figure out what belongs with what.

I would also move that line to be the first one of the code, before the for-loop.

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

This is a more compact and easier to follow version of the code above:

if (event.target.value=="Yes") {

    var layers = this.getOCGs();

    if (layers!=null) {

        for (var i=0; i<layers.length; i++) {

            if (layers.name=="WR1") layers.state=false;

            if (layers.name=="CL1") layers.state=false;

            if (layers.name=="NC1") layers.state=false;

            if (layers.name=="WR2") layers.state=false;

            if (layers.name=="CL2") layers.state=false;

            if (layers.name=="NC2") layers.state=false;

            if (layers.name=="WR3") layers.state=false;

            if (layers.name=="CL3") layers.state=false;

            if (layers.name=="NC3") layers.state=false;

        }

    }

}

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

Thanks for this revision. Unfortunately it doesn't seem to be working for me now. The layers are staying switched on when the reset button is clicked.

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 ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

That's because this field is not a check-box, but a button, so it doesn't have any value.

Remove the first and last lines of the code 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
Community Beginner ,
Jan 04, 2019 Jan 04, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much. That's exactly what I wanted it to do!

Have a great day!

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