[thelist] Using variables in DOM object names

Joe Ngo chilijoe at gmail.com
Wed Jul 13 08:30:46 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;
        }


On 7/13/05, Christian Heilmann <codepo8 at gmail.com> wrote:
> Well, I don't see you using it...
> 
> function SetFields()
> {
>         var fieldnames = new Array("firstname","lastname","city")
>         for (i=0; i<fieldnames.length; i++)
>         {
>                 window.opener.document.getElementById(fieldnames[i]).value=document.getElementById(fieldnames[i]).value;
>         }
>         window.close();
> }
> 
> works perfectly here.
> You accessed objects of the window that are really objects of the document.
> 
> More fabulous adventures in how to reach what you want to change:
> http://www.onlinetools.org/articles/unobtrusivejavascript/chapter2.html
> 
> and eval is evil, btw:
> http://blogs.msdn.com/ericlippert/archive/2003/11/01/53329.aspx
> 
> 
> --
> Chris Heilmann
> Blog: http://www.wait-till-i.com
> Writing: http://icant.co.uk/
> Binaries: http://www.onlinetools.org/
> 
> --
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
> 
> 
> 


-- 
Take back the web!
http://www.spreadfirefox.com


More information about the thelist mailing list