Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!news.xs4all.nl!not-for-mail Newsgroups: alt.comp.lang.javascript,comp.lang.java.help Subject: Re: Problem in other browsers than Internet Explorer From: "Evertjan." References: <1752b646-2ce0-47ab-b9a0-1f006a758aed@f39g2000prb.googlegroups.com> Message-ID: User-Agent: Xnews/2009.05.01 Date: 02 Jul 2011 10:05:27 GMT Lines: 49 NNTP-Posting-Host: 188.142.37.124 X-Trace: 1309601127 news2.news.xs4all.nl 21882 ehannivo/188.142.37.124:59676 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:810 Ilya Shambat wrote on 02 jul 2011 in comp.lang.javascript: > I have code that works when I use Internet Explorer, but does not work > when I use Mozilla Firefox. > > The code is > > var textpassed = document.getElementById(fieldname).value; > > where fieldname is the name of the field as defined in the document. "fieldname" has no meaning in html, do you mean field like in ? getElementById() needs the id of a tag, not the name. Only clumsy IE seems to allow the name if an id is absent. [better forget about that and never code for IE alone again.] > Any other operations using similar code, such as > > alert ("In field " + document.getElementById(fieldname).name); > > returns valid results in Internet Explorer but not in Mozilla Firefox. > > Would anyone know the reasons for this, and is this possible to get > around? Use correct code and do not set your trust on the silly IE shortcuts: document.getElementById(myId) ============ Understand that a name can be given to multiple tags, so ths will return an array, and you would have to specify the member: document.getElementsByName(myName)[3] [This does not exist: getElementByName] -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)