check / uncheck all checkboxes

This script can check all / uncheck all checkboxes like in webmail
<SCRIPT LANGUAGE="JavaScript">
<!-- 	
// http://www.fornewbie.com
// This script checks and unchecks boxes on a form
<!-- Begin
function toggle(checks, src){
if (src.checked) {
  for(var i=0;i<checks.length;i++)
    {
      checks[i].checked=false;
    }
  } else {
      for(var i=0;i<checks.length;i++)
      {
        checks[i].checked=true;
      }
    }
}
//  End -->
</script>

Usage :
<form action="" method="post" name="form2">
<table width="100%" >
<tr>
<td><input type="checkbox" name="checkbox[]" value="1"></td>
<td>New York</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox[]" value="2"></td>
<td>London</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox[]" value="3"></td>
<td>Tokyo</td>
</tr>
<tr>
<td><input type=checkbox id="ToggleCheck" value="Toggle" onMouseUp="toggle(document.getElementsByName('checkbox[]'), document.getElementById('ToggleCheck'))">Check All</td>
<td><input name="Submit" type="submit" id="Submit" value="Submit""></td>
</tr>
</table>
</form>
Sample :
New York
London
Tokyo
Check All

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.