Jump to content

Controlling Checkboxes


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>

Edited by GH4
Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...