sradha
08-26-2010, 11:48 AM
<script 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>
<body>
<form name="myform" action="checkboxes.asp" method="post">
<input type="checkbox" name="list" value="1">Java<br>
<input type="checkbox" name="list" value="2">Javascript<br>
<input type="checkbox" name="list" value="3">Active Server Pages<br>
<input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.myform.list)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.myform.list)">
<br>
</form>
This code snippet is not clear to me...I didn't understand what is happening in the "for loop" within the script tag...what does 'field' refer to?
In the onclick event of button the argument passed is "document.myform.list"..If I am writing javascript in a separate file how will I pass those arguments?
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>
<body>
<form name="myform" action="checkboxes.asp" method="post">
<input type="checkbox" name="list" value="1">Java<br>
<input type="checkbox" name="list" value="2">Javascript<br>
<input type="checkbox" name="list" value="3">Active Server Pages<br>
<input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.myform.list)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.myform.list)">
<br>
</form>
This code snippet is not clear to me...I didn't understand what is happening in the "for loop" within the script tag...what does 'field' refer to?
In the onclick event of button the argument passed is "document.myform.list"..If I am writing javascript in a separate file how will I pass those arguments?