...

View Full Version : document.myform.list



sradha
08-26-2010, 12:48 PM
<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?

Arty Effem
08-26-2010, 03:25 PM
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?The parameter being passed is the group of elements with the name list.
Within the scope of the form it could have been written
onClick="uncheckAll( list )">

If I am writing javascript in a separate file how will I pass those arguments?The form (or its element) would be better referenced by ID, but in its current state:


document.forms.myform.UnCheckAll.onclick = function(){ uncheckAll( this.form.list ); };



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum