These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript "No preference" checkbox

AntoonG
Registered: Mar 13 2011
Posts: 2

Hi,
 
I have a Acrobat form with a question with 4 mutually non exclusive choices (= checkboxes cb1 to cb4) and a 'no preference' choice (cb5):
 
cb1 : Choice A
cb2 : Choice B
cb3 : Choice C
cb4 : Choice D
cb5 : No preference
 
I have little javascript knowledge, but from reading the forum, I already got the following script (which runs on 'Mouse Up') together:
 
// Get a reference to each check box
var f1 = getField("cb1");
var f2 = getField("cb2");
var f3 = getField("cb3");
var f4 = getField("cb4");
var f5 = getField("cb5");
 
// Uncheck cb5 if cb1, cb2, cb3 or cb4 was selected/deselected
if (event.target === f1 || event.target === f2 || event.target === f3 || event.target === f4) {
f5.value = "Off";
}
 
// Uncheck cb1, cb2, cb3 and cb4 if cb5 was selected/deselected
if (event.target === f5) {
f1.value = "Off";
f2.value = "Off";
f3.value = "Off";
f4.value = "Off";
}
 
Now, I'd also like to add some script which, if a user checks cb1, cb2, cb3 and cb4 (which actually means that this user has no preference), unchecks checkboxes cb1 to cb4 and checks cb5.
 
Any hints on how to do this would be much appreciated!

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You might want to look at using exclusionary groups of radio buttons or check boxes. The exclusionary group is a series of radio buttons or check boxes that have the same field name but each individual button or widget has a different export value. The group of buttons also only allows one radio button or check box to be checked at one time. In JavaScirpt if one focuses on the object of the group, the value JavaScript sees is the export value of the checked button or the sting "Off" if no button is selected. It is also possible to check each individual button in JavaScript.

Use of the exclusionary group greatly simplifies the coding and test of radio buttons and check boxes.

The difference between radio buttons and check boxes is that once a radio button has been selected, the group can not be cleared by checking the checked button. With check boxes, one can check the selected check box and that check box will be unchecked and no other check box needs to be checked. Radio Buttons obtained their name from the old analog radios with preset buttons that always required one button to be selected and it was not easy to deselect all of the buttons at one time.

George Kaiser

AntoonG
Registered: Mar 13 2011
Posts: 2
Thanks, but I don't understand how exclusionary check boxes solve the issue. I want to allow that e.g. cb1, cb2 and cb3 are checked at the same time (or any other combination of 3 or less in the group of cb1, cb2, cb3, cb4).

However, if all 4 of them are checked, then cb5 should become checked and the rest unchecked.