Logo
doctype [?]
[strict] [loose] [none]

Check Box Groups


Including The Script

Include a reference to the js file in the HEAD of your HTML page.

<script type="text/javascript" src="checkboxgroup.js"></script>

Creating The Object

var myOptions = new CheckBoxGroup();

Adding Checkboxes To The Group

Use the addToGroup method of the object to add checkboxes into the group object. You may make multiple calls to this function, and/or pass multiple arguments. You may specify field names exactly, or use a wildcard at the beginning or end of the name.

myOptions.addToGroup("cb1","cb2","optionset*");
myOptions.addToGroup("*checkbox");

Using A Control Box

If your group has a control box, for example "select all", its name needs to be explicitly set.

myOptions.setControlBox("masterCheckboxName");

There are two ways that a control box can interact with the group - either "all" mode or "some" mode.

all (default)Checking the box will select all the other boxes. Unchecking it will uncheck all the group checkboxes. Selecting all the checkboxes in the group will automatically check the control box.
someChecking any checkbox in the group will check the control box. The control box may not be unchecked if any option in the group is still checked. If no boxes in the group are checked, you may still check the control box.
myOptions.setMasterBehavior("some");

Restricting Check Count

You may set the maximum number of boxes in the group which are allowed to be checked by using the setMaxAllowed method. You may pass a second argument which is an alert message to be displayed to the user if they exceed this limit.

myOptions.setMaxAllowed(2);
myOptions.setMaxAllowed(3,"You may only select 3 choices!");

Adding onClick Handlers To Checkboxes

After defining the group and behavior, you must insert an action into EVERY checkbox's onClick event-handler. Just specify the name of the group object that the checkbox belongs to, and pass it 'this' as the argument.

<INPUT TYPE="checkbox" NAME="cb1" onClick="myOptions.check(this)">