Multiple checkboxes unchecked by one checkbox

I have a form with four checkboxes three of the four can be checked together in different combinations if the fourth one is checked the other three would be unchecked. For example if someone checks one and two then checks four then one and two would be unchecked automatically. In other words one, two, and three can be checked in different combinations, If number four is checked and any of the others are checked then they would be unchecked automatically or if checkbox four is checked first then as soon as one of the other three are checked four would then be unchecked.


Zach Stevens


8 Answers

Voted Best Answer

I apologize, my code is actually incomplete, because it does not take care of the hiding of the GROUP fields when chacking a box unchecks another one.

That means that with every

this.getField("box_n").value = "Off"

line (where _n stands for the number of the box), there must also be a

this.getField("GROUP_m").display = display.hidden

line (where _m stands for the according group).

That now should get things working properly.

Max Wyss.



By Max Wyss   

You are going to have write some custom JavaScript for the fields to control the checked status of the other fields. I would use the On Blur action.


George Kaiser   

In the MouseUp event of box 4 you would add the following script (assuming your fields are named "box1", "box2", and "box3":

if (event.target.value != "Off") {
this.getField("box1").value = "Off" ;
this.getField("box2").value = "Off" ;
this.getField("box3").value = "Off" ;
}

Now, if you want to uncheck box4 when checking one of the other boxes, you would add the following to their MouseUp events:

if (event.target.value != "Off") {
this.getField("box4").value = "Off" ;
}

and that should do it…

Note that this works when the values of the boxes are only manually changed (as opposed via other scripts).

Hope this can help.

Max Wyss.


Max Wyss   

Max your JavaScript work properly but it broke another JavaScript I was using to showing hide fields with the same checkboxes. For example this is what I have in checkbox three and four.
(Checkbox 4)
var showHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
this.getField("GROUP0").display = showHide;
if (event.target.value != "Off") {
this.getField("box1").value = "Off" ;
this.getField("box2").value = "Off" ;
this.getField("box3").value = "Off" ;
}

(Checkbox 3)
var showHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
this.getField("GROUP3").display = showHide;
if (event.target.value != "Off") {
this.getField("box4").value = "Off" ;
}
The JavaScript that you put together worked correctly to uncheck the boxes but when the boxes unchecked group0 or any of the other groups did not go hidden the only way to make them hidden again is to check and uncheck the box manually. I have tried using event.target.isBoxChecked(Off) and that did not fix the issue. Max again your solution did give me an answer for my original question and I will market as the correct solution but it is opened up another question and I didn't want to start a whole new thread for it.


Zach Stevens   

OK, that's not nice that the script got broken, but it is not such a big deal to merge the scripts, because isBoxChecked() is kind of similar to value != "Off".

The code for box4 would then look like this:

if (event.target.value != "Off") {
this.getField("box1").value = "Off" ;
this.getField("box2").value = "Off" ;
this.getField("box3").value = "Off" ;
this.getField("GROUP0").display = display.visible ;
} else {
this.getField("GROUP0").display = display.hidden ;
}


and for box3:

if (event.target.value != "Off") {
this.getField("box4").value = "Off" ;
this.getField("GROUP3").display = display.visible ;
} else {
this.getField("GROUP3").display = display.hidden ;
}


And that should take care of the things. Just make sure that the initial condition is correct, so that the GROUP fields will show correctly right away, and switch with checking the boxes.

Hope this can help.

Max Wyss.


Max Wyss   

I appreciate your help but this script doesn't turn the checkboxes on and off properly or show and hide the groups. Before the form is filled out the checkboxes are unchecked and the groups are hidden so I tried to reverse this portion of the script to see if it would work and it didn't.
this.getField("GROUP0").display = display.hidden ;
} else {
this.getField("GROUP0").display = display.visible ;
}
The way that I have the groups hidden is by hiding the group items in properties. I have tried making them visible to see if that would fix the issue and it did not.
What were you referring to when you said ”just make sure that the initial condition is correct, so that the GROUP fields will show correctly right away, and switch with checking the boxes”?
Again I appreciate your help


Zach Stevens   

I reset all of the hidden values to visible save the PDF and reopened it and now everything is working except when the checkbox is unchecked by the action of another checkbox the group does not go back to being hidden. In other words the same problem I was having before merging the two scripts.


Zach Stevens   

Max you are a life saver it worked thanks for all of your help.


Zach Stevens   


Please specify a reason: