faqts : Computers : Programming : Languages : PHP : Not Quite PHP : Javascript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 16 people (56%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I select all check boxes in a form?

Sep 20th, 1999 23:05
Nathan Wallace, Richard Feather


You'll need to do it with Javascript on the client...

Something like...

    function checkAll()
    {
        for(var i=0;i<document.element.foo.elements.length;i++)
        {
            var e = document.foo.elements[i];
            if (e.name!='allbox')
                e.checked = document.foo.allbox.checked;
        }
    }

where the name of the form is 'foo'...  I'm doing this from memory and 
it isn't exact (it loops over all elements) so you might need to work 
with it a little.  But as I look at it it should work okay.