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

  1. 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.

  1. 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.)
  2. Also note the instructions included within the comments of the code above.

 

 

 

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!