I have three checkboxes in a group. Can I make them dependent on each other so that if checkbox 1 is checked, you can't check checkbox 2 or 3. If checkbox 2 is checked, you can't check 1 and 3, etc? In other words, of the three checkboxes, you can only check one option and if you check more to receive an error?.
If it is a case where you only want to allow the user to choose one option out of a group, then you might want to use a Radio Group instead of a checkbox group. If there is some other reason why you need those checkboxes to be conditional however (for example, for a following visibility rule), then you can do so by putting a custom validation in the checkbox group.
In the Validation section at the bottom of the checkbox element, click on the CUSTOM button. In the textarea that opens, paste in the code below. Then make changes as noted in the CHANGES REQUIRED section below.
function ff_mygroup_validation(element, message) { // initial checked states for your box, add more or less, depending on your amount of checkboxes of your group // if you have checkboxes that are initially checked, set the corresponding value here to "true" var checkedBoxes = [false,false,false]; for(var i = 0; i < document.ff_form85.elements.length; i++) { if(document.ff_form85.elements[i].type == "checkbox" && document.ff_form85.elements[i].name == "ff_nm_mygroup[]") { if( document.ff_form85.elements[i].checked ) { checkedBoxes[i] = true; } else { checkedBoxes[i] = false; } } } if (message=='') message = element.name+" You can only check one box!.\n"; // the rules apply here // add or remove rule depending on your amount of checkboxes if(checkedBoxes[0] && ( checkedBoxes[1] || checkedBoxes[2] ) ) return message; if(checkedBoxes[1] && ( checkedBoxes[0] || checkedBoxes[2] ) ) return message; if(checkedBoxes[2] && ( checkedBoxes[0] || checkedBoxes[1] ) ) return message; return ''; } // end validation
CHANGES REQUIRED
- Replace all instances of ff_form85 in the code above with the formname of your form. To find the formname code, view the form's sourcecode. Then search for this code:
ff_processor.form_id='
The generated formname will follow immediately after that.
- Replace all instances of mygroup in the code above with the name of your checkbox group. (You can find the name in the field underneath the LABEL field in the element properties screen.)
- Also note the instructions included within the comments of the code above.