Java script to show/hide layers and checkboxes
I'm trying to control the visibility of certain checkboxes and layers on my PDF form according to what is selected in a drop down menu. I've found 2 scripts; one to show/hide the layers and one to show/hide the checkboxes. I'm a novice when it comes to java scripting. How do I combine them?
If "Option1" is selected from the dropdown, the layer of the same name along with Box3 and Box4 should show.
If "Option2" is selected, the layer of the same name along with Box1 and Box2 should show.
If "-Select-" is selected (default), none of the options above should show.
Layers script:
var layers = this.getOCGs();
var v = event.value;
for (var i = 0; i < this.layers.length; i++) {
if (layers[i].name == “Option1” && v == "Option1") {
layers[i].state = true;
}
else if (layers[i].name == “Option2” && v == "Option2") {
layers[i].state = true;
}
if (layers[i].name == "Option1" && v == "Option2") {
layers[i].state = false;
}
else if (layers[i].name == "Option2" && v == "Option1") {
layers[i].state = false;
}
if (layers[i].name == "Option1" && v == "-Select-") {
layers[i].state = false;
}
if (layers[i].name == “Option2” && v == "-Select-") {
layers[i].state = false;
}
}
Checkbox script:
var v = event.value;
if(v == "-Select-"){
this.getField(“Box1”).display = display.hidden;
this.getField("Box2").display = display.hidden;
this.getField("Box3”).display = display.hidden;
this.getField("Box4").display = display.hidden;}
if(v == "Option2"){
this.getField("Box1").display = display.visible;
this.getField("Box2").display = display.visible;
this.getField("Box3”).display = display.hidden;
this.getField("Box4").display = display.hidden;}
if(v == "Option1"){
this.getField("Box1").display = display.hidden;
this.getField("Box2").display = display.hidden;
this.getField("Box3”).display = display.visible;
this.getField("Box4").display = display.visible;}
Any help or advice would be greatly appreciated!
Thanks,
Trisha
