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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    check all checkboxes

    I am trying to get a link that when clicked it will check all the checkboxes in my form.

    My problem is that my values are stored in an array:
    <INPUT TYPE=\"checkbox\" name=\"emailArray[]\" value=\"$email\">


    print"<br><a href=\"#\" onClick=\"checkAll()\">check all</a><br>";

    Here is my javascript function :
    function checkAll(){
    alert('hi');
    var df = document.selectEmailForm.elements;

    for (var i = 0; i < df.length; i++) {
    if (df[i].name == "emailArray[]" ) {
    document.selectEmailForm.emailArray[i].checked=true;
    }
    }
    }

    Any ideas? Any help is greatly appreciated.
    Thanks for your time!

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question

    Hmz..I'm wondering why are you using emailArray[] as a name? Wouldn't only emailArray or aEmail be better, because brackets has no function in this case?

    Also:
    Code:
    
    <script type="text/javascript">
    function zCheckAll(oForm)
    {
    	var oElems = oForm.elements;
    
    	for (var iI=0;oElems.length>i;i++)
    	{
      		if (oElems[iI].type == "checkbox")
    			oElems[iI].checked = true;
    	}
    }
    </script>
    function is launched eg :
    <a href="#" onclick="zCheckAll(yourFormName);" title="Check all boxes">Check 'em</a>

    Note : yourFormName is inserted in code without parenthesis, like myForm, not "myForm".
    Zvona
    First Aid for
    Web Design

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    In PHP when you submit a form set up in this manner you will automatically have an array properly set up named $emailArray when it gets to the server-side. It is very handy!

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up thye solution

    well i needed the same thing because of php, so i was searching it and i saw your thread. so i used your script to make it work for both of us. here it is:

    <script language=javascript>
    <!--
    function checkall()
    {
    var df=document.form1.elements;
    for(var i=0;i<df.length;i++)
    {
    //alert(df[i].name);
    df[i].checked=true;
    }
    }

    function uncheckall()
    {
    var df=document.form1.elements;
    for(var i=0;i<df.length;i++)
    {
    //alert(df[i].name);
    df[i].checked=false;
    }
    }
    -->
    </script>
    /* where form1 is of course the name of your form */

  • #5
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Great

    I have been searching for a code like this for about a year now!!! Thank you guys so much! I greatly appreciate it!


  •  

    Posting Permissions

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