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
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    checkbox problem

    i have a form with a lot of checkboxes
    how can i click a button or link to check all the checkboxes
    flying dagger

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    you gotta use javascript to do that im pretty sure it cannot be done in html.

    something like this might do it:

    Code:
    <script language="Javascript">
    function checkAll(theForm, cName, check) {
        for (i=0,n=theForm.elements.length;i<n;i++)
            if (theForm.elements[i].className.indexOf(cName) !=-1)
                theForm.elements[i].checked = check;
    }
    
    </script>
    <form id="myform">
    <input type="checkbox" class="filecheck"><br>
    <input type="checkbox" class="filecheck"><br>
    <input type="checkbox" class="filecheck"><br>
    <input type="checkbox" class="filecheck"><br><br>
    <a href="javascript:checkAll(document.getElementById('myform'), 'filecheck', true);">select all</a>&nbsp;
    <a href="javascript:checkAll(document.getElementById('myform'), 'filecheck', false);">select none</a>
    </form>
    hope this helps.

    Jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P


  •  

    Posting Permissions

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