i want to toggle checkboxes when i toggle

lets say i have multiple checkboxes...

and i have a single checkbox that when i check, there will be a function that will make them all checked or unchecked.
how will i make it?

while (condition) {
$i++;
echo "
<tr>
<td>$i &nbsp;</td>
<td valign=\"top\"><input type=\"checkbox\" name=\"$R\" value=\"???"></td>
<td valign=\"top\">Item $i</td>
<tr> ";
}

<form action="urlxxx.php" method="post" target="_self">
<table>
<tr>
<td><input type="checkbox" name="toggle" value="toggle">Toggle All &nbsp;&nbsp;</td>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>

here is some code i got somewhere to output the checkboxes(results from a query). but how do i make an event where i click the checkbox on the bottom so that all the checkboxes will toggle checked/unchecked.

thanx for any help

    you need to use a javascript, that's the easiest way. Not too hot on java, so i can't help there, sorry.

      but is there a way to do it using php?

      i dont know squat about jscript....
      and im just learning php...
      this is so frustrating......

        php runs server side (afaik) not browser side, so you can't have it work like that. I searched for what you need:

        put this in the header:

        <SCRIPT LANGUAGE="JavaScript">
        
        <!-- Begin
        var checkflag = "false";
        function check(field) {
        if (checkflag == "false") {
        for (i = 0; i < field.length; i++) {
        field[i].checked = true;}
        checkflag = "true";
        return "Uncheck All"; }
        else {
        for (i = 0; i < field.length; i++) {
        field[i].checked = false; }
        checkflag = "false";
        return "Check All"; }
        }
        //  End -->
        </script>
        

        This is used within the body tags:

        <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">Applets<br>
        <input type=checkbox name=list value="5">PHP<br>
        <br>                                                    
        <input type=button value="Check All" onClick="this.value=check(this.form.list)"> </td></tr> </table> </form> </center>

        hope that helps.

          Write a Reply...