Simple java script for select all Check box


Hi,... this is a select  all check box in java script. this is a toggle function .this coding is get by name .to checked all  check box and unchecked check box.it's contain simple coding to select and unselected a check box . on click  select  all  check box to checked to all box and   check box  name  important (all)  to  select and un select  check boxes..,,


 Javascript:


checkboxes = document.getElementsByName('all');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;

Demo   

Source Code:


<html>
<head>
<title>Select All Check box</title>
<!-- Start of JavaScript -->
<script language="JavaScript">
function toggle(source)
{
checkboxes = document.getElementsByName('all');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
<!--End of JavaScript -->

</head>
<body>
<div align="center" style="margin-top:100px;">
<input type="checkbox" onClick="return toggle(this);" />
<span style="color:#09F">Select All</span><br/>
<input type="checkbox" name="all" value="option1"> Option 1<br/>
<input type="checkbox" name="all" value="Option2"> Option 2<br/>
<input type="checkbox" name="all" value="Option3"> Option 3<br/>
<input type="checkbox" name="all" value="Option4"> Option 4<br/>
</div>
</body>
</html>