JC5 Posted May 25, 2009 Share Posted May 25, 2009 (edited) 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 May 25, 2009 by GH4 Link to comment Share on other sites More sharing options...
Ingolme Posted May 25, 2009 Share Posted May 25, 2009 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 More sharing options...
JC5 Posted May 25, 2009 Author Share Posted May 25, 2009 oK thanks. Got it working Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now