Skip to main content
Known Participant
January 4, 2019
Answered

Resetting layers

  • January 4, 2019
  • 1 reply
  • 1089 views

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

This topic has been closed for replies.
Correct answer try67

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.


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.

1 reply

Bernd Alheit
Community Expert
Community Expert
January 4, 2019

Where is the reset button?

Known Participant
January 4, 2019

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.

try67
Community Expert
Community Expert
January 4, 2019

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.