Page 1 of 1

having one checkbox automatically check off others

Posted: Mon Jun 30, 2003 12:23 pm
by akhalsa
I am trying to write a script in php that has a huge number of options to be checked off. To simplyfy this, I have them grouped off. Next to each group title, there is a checkbox, and next to each option in the group there is a checkbox. I want to set it so that when a user clicks on the checkbox next to the group title, all the checkboxes below are automatically checked off. Effectivly this is the same as the delete all checkbox many online email clients like yahoo use, but i couldnt find how it was done. Thanks

Posted: Mon Jun 30, 2003 1:01 pm
by m3rajk
javascript

try onChange

others tat might work are onClick, onFocus, and onSelect

Posted: Mon Jun 30, 2003 3:27 pm
by phice

Code: Select all

<html>
<head>
<script language="JavaScript">
var checkflag = "false";
function check(field)
&#123;
  if (checkflag == "false")
  &#123;
    for (i = 0; i < field.length; i++)
    &#123;
      field&#1111;i].checked = true;
    &#125;

    checkflag = "true";
    return "Uncheck All";
  &#125;
  else
  &#123;
    for (i = 0; i < field.length; i++)
    &#123;
      field&#1111;i].checked = false;
    &#125;
  
    checkflag = "false";
    return "Check All";
  &#125;
&#125;
</script>
</head>

<body>

<center>
<form name=myform action="" method=post>
<table>
<tr><td>
<b>Your Favorite Scripts & Languages</b><br>
<input type=checkbox name=list value="1">Java<br>
<input type=checkbox name=list value="2">JavaScript<br>
<input type=checkbox name=list value="3">ASP<br>
<input type=checkbox name=list value="4">HTML<br>
<input type=checkbox name=list value="5">SQL<br>
<br>                                                    
<input type=checkbox onClick="this.value=check(this.form.list)"> Check All
</td></tr>
</table>
</form>
</center>
</body>
</html>