Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21210
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: getElementById or forms['form'].elements....? |
| Date | 2013-09-08 19:17 +0100 |
| Organization | Home |
| Message-ID | <yMQqIqZf8LLSFwc5@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <k8im29d9ajaespd888g0se3fhhj589u4kg@4ax.com> |
In comp.lang.javascript message <k8im29d9ajaespd888g0se3fhhj589u4kg@4ax.
com>, Sat, 7 Sep 2013 08:45:14, Ed Jay <edMbj@aes-intl.com> posted:
>I'm being told to us the identifier:
>document.getElementById("foo_box").whatever;
>
>instead of:
>document.forms['form'].elements['foo_box'].whatever;
>
>Why?
Even the simple-minded can, in simple cases, get the former to work.
But, for those capable of making proper use of it, the structured
approach is better, if sensibly applied.
Commonly, a script will make a number of references to elements in one
form before going on to another; so instead of writing
... = document.forms['form'].elements['foo_box'].this
... = document.forms['form'].elements['foo_box'].that
...
document.forms['form'].elements['foo_box'].tother = ...
one would first think of writing
F = document.forms['form']
... = F.elements['foo_box'].this
... = F.elements['foo_box'].that
...
F.elements['foo_box'].tother = ...
and then
X = F.elements['foo_box']
and so on.
Then one can have a set of similar forms, similarly generated, which can
be handled with one set of code which is given a reference to the
current form. Consider a case such as
<http://www.merlyn.demon.co.uk/holidays.htm>, and its function MakeForm
(Aside : the page was written before I knew about building DOM tree
branches with function calls). While there, check if possible your
local holidays.
You should not name a form 'form'. It may be perfectly legal script.
but it makes editing harder, since a simple search for 'form' will find
both, and possibly "forms" and "Inform" too. Call it "Frm" and that
problem cannot occur.
--
(c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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