Let's take a look at a simple working example of this:
Now here's the script that you attach to the bottom of any page where you want to limit selections.
Next you make sure that your form contains somewhere to display the error message. The code I usually use looks like this:
We also need to make sure that the checkboxes are grouped together in a way that the script can identify them. In my example I have done this by wrapping all the checkboxes in a group within a fieldset and giving that fieldset an id.
All that remains to be added is the call(s) to limitSel() to limit the selections in your form. As the fieldset defining my 'boxes' group has an id of 'boxes' and we only want to allow two checkboxes in this group to be selected we call the function like this:
limitSel('boxes',2,'Please choose only 2 box checkboxes.');
This article written by Stephen Chapman, Felgall Pty Ltd.