Don't undestand how this works
Good afternoon everybody,
I am experimenting and learning with Adobe Acrbat Pro, Javascript Forms. Lately, I've been working on On/Off buttons that turn on and off other selected buttons.
I've construdted a code with checkboxes, which each one turns On the lower ones, and Off the higher ones. Therefore, clicking on any would always show the previews options checked, while the later off.
For example, Pressing on Button1 would keep Buttons2-5 off. Button3 turns one Button1-2 and off Button4-5. And Button5 would turn on Button1-4.
Thus, Button1 is:
var x = this.getField("Button1").valueAsString;
if (x.value == "1")
{
this.getField("Button2").value = "Off";
this.getField("Button3").value = "Off";
this.getField("Button4").value = "Off";
this.getField("Button5").value = "Off";
}
else
{
this.getField("Button2").value = "Off";
this.getField("Button3").value = "Off";
this.getField("Button4").value = "Off";
this.getField("Button5").value = "Off";
}
Thus, Button3 is:
var x = this.getField("Button2").valueAsString;
if (x.value == "1")
{
this.getField("Button1").value = "1";
this.getField("Button2").value = "1";
this.getField("Button4").value = "Off";
this.getField("Button5").value = "Off";
}
else
{
this.getField("Button1").value = "1";
this.getField("Button2").value = "1";
this.getField("Button4").value = "Off";
this.getField("Button5").value = "Off";
}
Thus, Button5 is:
var x = this.getField("Button5").valueAsString;
if (x.value == "1")
{
this.getField("Button1").value = "1";
this.getField("Button2").value = "1";
this.getField("Button3").value = "1";
this.getField("Button4").value = "1";
}
else
{
this.getField("Button1").value = "1";
this.getField("Button2").value = "1";
this.getField("Button3").value = "1";
this.getField("Button4").value = "1";
}
So when I just left the If statement without the Else, it just breaks the code. Not having an If statement nor Else, also behaves that way.
Something, I'd like is that when the Checkbox is turned off it turns off all checkboxes, but it affects the On statement, keeping it turned off.
My question: Why does it happen that way? is there another way of doing it without so many lines? and last, how could one make it that the Off state turns off the other Checkboxes without affecting the On state?
No need to hurry, I'm just trying to learn and understand, and do love your input, opinions, help and explanations.
THANK YOU SO MUCH!
