having one checkbox automatically check off others

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
akhalsa
Forum Newbie
Posts: 2
Joined: Wed Jun 25, 2003 2:47 pm

having one checkbox automatically check off others

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

javascript

try onChange

others tat might work are onClick, onFocus, and onSelect
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

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