Web Analytics Made Easy -
StatCounter check all checkboxes - CodingForum

Announcement

Collapse
No announcement yet.

check all checkboxes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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:
    [size=2]
    <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>[/size]
    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

    Comment


    • #3
      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!

      Comment


      • #4
        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 */

        Comment


        • #5
          Great

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

          Comment

          Working...
          X