JavaScript Check All / Uncheck All Boxes

 

This script will let you check all and uncheck all boxes in a form.

 

Example

Box one
Box two
Box three
Box four
Box five

 

Script Source

 

<The Form >

<form name="myform" action="" method="post">
<input type="checkbox" name="box" value="1">Box one<br>
<input type="checkbox" name="box" value="2">Box two<br>
<input type="checkbox" name="box" value="3">Box three<br>
<input type="checkbox" name="box" value="4">Box four<br>
<input type="checkbox" name="box" value="5">Box five<br>

<input type="button" name="CheckAll" value="Check All"
onClick="checkBox(document.myform.box)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckBox(document.myform.box)">
<br>
</form>

 

<The JavaScript >

<script type="text/javascript">
<!--
// www.wizzardweb.co.uk

function checkBox(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}

function uncheckBox(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
// End -->
</script>

 

Please let me know if this script was helpful to you.

[rating]