Jump to content

Controlling Checkboxes


JC5
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...