[thelist] Using variables in DOM object names

Christian Heilmann codepo8 at gmail.com
Wed Jul 13 09:34:45 CDT 2005


> The original code indicates the form fieldnames are in name
> attributes, not id. As an alternative, not saying a better approach
> but probably more backward-compatible:
> 
>         var fieldnames = new Array("firstname","lastname","city")
>         for (var i=0; i<fieldnames.length; i++)
>         {
> 
> window.opener.document.studentReg.elements[fieldnames[i]].value=document.studentSelect.elements[fieldnames[i]].value;
>         }

Yes, but labels only connect to IDs, not name attributes, therefore if
you want to create an accessible, modern form, you need IDs anyway.
Actually you should also check that the elements are existant before
trying to change them.

-- 
Chris Heilmann 
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/  
Binaries: http://www.onlinetools.org/


More information about the thelist mailing list