Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    God's Own Country
    Posts
    87
    Thanks
    6
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    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 )">
    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 ); };


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •