This code demonstrates how to check or uncheck all checkboxes on a click of a button in JavaScript:





Code:

<script language="JavaScript" type="text/javascript">
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
</script>
...
<form name="form1" method="post" action="">
<input type="checkbox" name="mybox">
<br>
<input type="checkbox" name="mybox">
<br>
<input type="checkbox" name="mybox">
<br>
<br>
<input type="button" name="b1" value="Check All" onClick="checkAll(document.form1.mybox)">
<input type="button" name="b12" value="Uncheck All" onClick="uncheckAll(document.form1.mybox)">
</form>