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
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    Checkbox check all

    All,
    I have the following checkbox code:
    PHP Code:
    echo "<input name=\"picbigid[]\" type=\"checkbox\" value=\"$pic[src_big]\">"
    I then want to select all the checkboxes so I have this code:
    [PHP]
    echo "<input type=\"button\" name=\"CheckAll\" value=\"Check All\" onClick=\"checkAll(document.photos.picbigid)\">&nbsp;&nbsp;<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\" onClick=\"uncheckAll(document.photos.picbigid)\">";
    [PHP]

    My JS function is:
    Code:
    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 ;
    }
    If I do it like this:
    PHP Code:
    echo "<input name=\"picbigid\" type=\"checkbox\" value=\"$pic[src_big]\">"
    It works but I can't have it like that because the form posts to another PHP page that needs the input name as an array.

    Any ideas?

    Thanks!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts
    You need to use the square bracket notation.

    Code:
    onClick=\"checkAll(document.photos.elements['picbigid[]'])\"
    Look at my sig for more info of this technique.


  •  

    Posting Permissions

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