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


Groups > comp.lang.javascript > #21227

Re: getElementById or forms['form'].elements....?

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: getElementById or forms['form'].elements....?
Date 2013-09-09 13:50 +0200
Organization albasani.net
Message-ID <l0kcml$1cr$1@news.albasani.net> (permalink)
References (5 earlier) <XnsA2355B826FA0Aeejj99@194.109.133.133> <nuvo29lpuadoqhi8pfkhiuec5avvo1a1mu@4ax.com> <l0jc6c$hnt$1@news.albasani.net> <3llq29lqirq5ercvok4dsvle5bfmh50k9q@4ax.com> <XnsA2365F6BFDE4Aeejj99@194.109.133.133>

Show all headers | View raw


On 2013-09-09 09:22, Evertjan. wrote:
>>>If all the names are valid identifiers, it's much simpler to write
>>>
>>>  document.forms.myForm.elements.firstName.value
>>>
>>>The square brackets aren't needed.
>>>
>> Good info. Thanks.
> 
> It is bad info, IMHO.
> 
> The criterium for valuating code IN THIS NG is not just "does it work" but 
> more so is the shown code readable, understandable, adaptable, servicable 
> and educational.
> 
> Code cases IN THIS NG are examples for all users. It is in that sense 
> immaterial if you should think that code is "good" when it works just for 
> your personal "needs" in only Safari, and that bad  but "working" code is 
> good enough for you.
> 
> And the square brackets are NEEDED 
> when the string or serial number is a not a scripted litteral.

Which is why I wrote "If all the names are valid identifiers".

> Examples:

[snipped; none of those properties are valid identifiers]

There are reasons for using the square bracket notation, but accessing
form elements like the ones seen in this thread is not one of them.


- stefan

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


Thread

getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-07 08:45 -0700
  Re: getElementById or forms['form'].elements....? Martin Honnen <mahotrash@yahoo.de> - 2013-09-07 18:07 +0200
    Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-07 10:36 -0700
  Re: getElementById or forms['form'].elements....? Ken <usenet-so@abdiassoftware.com> - 2013-09-07 13:58 -0500
    Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-07 13:18 -0700
      Re: getElementById or forms['form'].elements....? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-07 22:37 +0200
        Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-07 14:28 -0700
          Re: getElementById or forms['form'].elements....? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-08 08:59 +0200
            Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-08 06:55 -0700
              Re: getElementById or forms['form'].elements....? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-08 17:39 +0200
              Re: getElementById or forms['form'].elements....? Gregor Kofler <usenet@gregorkofler.com> - 2013-09-08 20:22 +0200
              Re: getElementById or forms['form'].elements....? Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 04:35 +0200
                Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-08 22:05 -0700
                Re: getElementById or forms['form'].elements....? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-09 09:22 +0200
                Re: getElementById or forms['form'].elements....? Stefan Weiss <krewecherl@gmail.com> - 2013-09-09 13:50 +0200
      Re: getElementById or forms['form'].elements....? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-07 22:49 +0200
        Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-07 14:25 -0700
          Re: getElementById or forms['form'].elements....? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-08 01:44 +0200
            Re: getElementById or forms['form'].elements....? John Harris <niam@jghnorth.org.uk.invalid> - 2013-09-08 10:04 +0100
              Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-08 06:56 -0700
                Re: getElementById or forms['form'].elements....? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-08 19:25 +0200
                Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-08 12:23 -0700
              Re: getElementById or forms['form'].elements....? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-09-09 19:56 +0100
                Re: getElementById or forms['form'].elements....? John Harris <niam@jghnorth.org.uk.invalid> - 2013-09-10 10:26 +0100
      Re: getElementById or forms['form'].elements....? Ken <usenet-so@abdiassoftware.com> - 2013-09-07 18:36 -0500
  Re: getElementById or forms['form'].elements....? Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-09-08 19:17 +0100
    Re: getElementById or forms['form'].elements....? Ed Jay <edMbj@aes-intl.com> - 2013-09-08 16:03 -0700

csiph-web