Sunday, January 23, 2011

Check/Uncheck all checkboxes based on one check box

<script language='JavaScript'>
checked = false;
function checkedAll ()
{
if (checked == false)
{
checked = true
}
else{checked = false
}
for (var i = 0; i < document.getElementById('myform').elements.length; i++) {
document.getElementById('myform').elements[i].checked = checked;
}
}
</script>


<form id="myform">
<input type="checkbox" name="foo"/>
<input type="checkbox" name="bar"/>
<BR>Check all: <input type='checkbox' name='checkall' onclick='checkedAll();'> </form>

No comments:

Post a Comment