[thelist] Finding all checkboxes or radios w same name, without document.all

sbeam sbeam at onsetcorps.net
Tue Feb 8 12:15:58 CST 2005

On Monday 07 February 2005 09:32 pm, Christian Heilmann wrote:
> >Use DOM method getElementsByName(). This is a W3C standard and I
> >believe supported by most modern browsers.
> >
> >  
> >
> believing is not knowing:
> http://www.quirksmode.org/dom/w3c_core.html

getElementsByName() does work fine in the listed browsers as long as you 
are only hoping to get form elements (it is very rare you'd have reason 
to give a name to anything else) - and if you don't have any overlap in 
your id/name attributes. Its a convenient way to check a set of 
checkboxes for instance - used it earlier today...
function checkAll(name) {
    checkColl = document.getElementsByName(name);
    for (i=0; i<checkColl.length; i++) {
        checkColl.item(i).checked = true; // I used item(), deal with it

More information about the thelist mailing list