Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-26-2010, 11:48 AM   PM User | #1
sradha
New Coder

 
Join Date: Feb 2010
Location: God's Own Country
Posts: 86
Thanks: 6
Thanked 0 Times in 0 Posts
sradha is an unknown quantity at this point
document.myform.list

Code:
<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?
sradha is offline   Reply With Quote
Old 08-26-2010, 02:25 PM   PM User | #2
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
Quote:
Originally Posted by sradha View Post
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 )">
Quote:
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:
Code:
document.forms.myform.UnCheckAll.onclick = function(){ uncheckAll( this.form.list ); };
Arty Effem is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:24 PM.


Advertisement
Log in to turn off these ads.