Jump to content

Controlling Checkboxes


JC5

Recommended Posts

Well, the behavior I'm looking for is this:I have 9 checkboxes. 1 to 8 are this and that. 9 is "all"All of them start out checked.When I uncheck one (any one) I want "all" (checkbox 9) to unchecked.When all are checked I want "all" (checkbox 9) to be checked.Can anyone help me?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"			"http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head><script type="text/javascript">function checkAll(check) {   for (i=0;i<10;i++) {	 if (check) { 		document.forms['thisone'].chbx[i].checked=true;		}	 else {		document.forms['thisone'].chbx[i].checked=false;		}	 }   }</script></head><body><form id="thisone"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"><input type=checkbox name="chbx" onClick="checkAll(false)" checked="checked"></form></body></html>

Link to comment
Share on other sites

Give the "all" box an id, for example id="all"When you click on any box that's not the "all" box, loop through all the checkboxes checking if they're checked or not. If any of them are not checked, then uncheck the "all" box.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...