Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16260

Re: document.elementname vs document.getElementById("id")

Path csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!.POSTED!not-for-mail
From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: document.elementname vs document.getElementById("id")
Date Sat, 29 Sep 2012 23:20:16 -0300
Organization Aioe.org NNTP Server
Lines 52
Message-ID <k48a8p$he5$1@speranza.aioe.org> (permalink)
References <k47drn$q7j$1@dont-email.me>
NNTP-Posting-Host bVlKTe5+J6NkVA9EqsSrJQ.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.javascript:16260

Show key headers only | View raw


On 29/09/2012 15:15, Denis McMahon wrote:
> Gaaah
>
> I'm fairly certain there's a reason that I think this is a "bad" idea ...
> apart from anything else an element name parameter is not guaranteed to
> be unique within a document - but I haven't easily been able to find a
> suitable reference for why not to do this, anyone got one?

Perhaps you are thinking of an ID instead of a name attribute.

>
> I'm arguing to replace using document.formname to identify forms with
> assigning an id to the forms involved and using document.getElementById
> ("formid").*, but the best arguments I can think of at the moment (more
> robust to future changes, better compatibility with developing standards,
> more maintainable) are butting up against "don't fix it until it needs
> fixing", whereas I prefer to prevent future breakage, rather than react
> to it.

document.formname is okay with HTML 4. You may use the W3C Markup 
Validation Service to check if an element should have an ID.

> I'm pretty certain that using document.getElementById("id") is better
> than using document.elementname, but at the moment I'm having trouble
> pointing to any sort of authoritative reference for this.

I recall MSIE used to pollute the global namespace with elements' names 
or IDs, that is, we could get a reference to an element using 
document.elementname or document.elementID. See 
<http://webbugtrack.blogspot.com.br/2007/09/bug-162-global-namespace-pollution-in.html>

The W3C standards compliant browsers use document.getElementById("ID") 
which is DOM level 1 (1998). Interestingly, Firefox still allows 
references in the old way (document.elementID or formName.elementName) 
when a page is rendered in "quirks mode".

>
> [1] It was document.all.formname which was breaking, a very senior coder
> (but not actually a web / js coder) "fixed" it by changing
> document.all.formname to document.formname, but I think the fix is almost
> as prone to future breakage as the original code was, and would prefer to
> see document.getElementById("formid") used instead, with approriate IDs
> allocated to forms.

Yes, this sort of "fix" is error prone. But a form's ID is not required 
in HTML 4 - only XHTML pages should require IDs:
<http://www.w3.org/TR/xhtml1/diffs.html>


-- 
--
Joao Rodrigues (J.R.)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-29 18:15 +0000
  Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-29 22:17 +0200
  Re: document.elementname vs document.getElementById("id") dann90038@gmail.com - 2012-09-29 16:21 -0700
  Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-29 23:20 -0300
    Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-29 19:53 -0700
    Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 11:02 +0300
      Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 13:10 +0000
      Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 13:14 +0000
        Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 17:20 +0300
          Re: document.elementname vs document.getElementById("id") Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-09-30 21:09 +0200
            Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 22:28 +0300
              Re: document.elementname vs document.getElementById("id") Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-09-30 21:53 +0200
            Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 21:53 +0200
          Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 22:07 +0000
            Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-01 06:23 +0300
              Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-01 08:11 +0000
                Re: document.elementname vs document.getElementById("id") Stefan Weiss <krewecherl@gmail.com> - 2012-10-01 11:25 +0200
      Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-30 15:10 -0300
        Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 20:43 +0200
    Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 12:22 +0200
      Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 13:44 +0300
        Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 13:46 +0200
  Re: document.elementname vs document.getElementById("id") Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-30 20:10 +0100

csiph-web