473,890 Members | 1,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.forms[formName].elemName

<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>
</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms['myForm'].elements['myElem']

But I have also seen the following:

document.forms['myForm'].myElem

Is the later correct usage or it just happens all browsers I've
tried with (IE 6, Mozilla 1.8, Opera 9.2 and Safari 3.1 on Windows)
support it for compatibility with existing Web content?

--
Stanimir
Jun 27 '08 #1
23 5933
Stanimir Stamenkov wrote:
<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>
A `div' element instead of `p' would be semantic here. It isn't exactly a
text paragraph, is it?
</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms['myForm'].elements['myElem']
Correct, as far as the standard goes. That the object referred to by
`document' implements the HTMLDocument interface of W3C DOM Level 2 HTML
in many cases has been a proprietary, yet reasonable design decision.
But I have also seen the following:

document.forms['myForm'].myElem

Is the later correct usage
I think it qualifies as deprecated usage by now.

http://docs.sun.com/source/816-6408-10/form.htm
or it just happens all browsers I've
tried with (IE 6, Mozilla 1.8, Opera 9.2 and Safari 3.1 on Windows)
support it for compatibility with existing Web content?
It would seem so.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-40002357
http://www.w3.org/TR/DOM-Level-2-HTML/glossary.html
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Jun 27 '08 #2
VK
On May 25, 3:12 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
<form name="myForm" action="...">
<p><input type="text" name="myElem"></p>
</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.forms['myForm'].elements['myElem']

But I have also seen the following:

document.forms['myForm'].myElem
The latter is a shortcut accessor to the same element. Most of the
time the shortcut form can be used to preserve your keyboard and your
finger tips :-) It is not the case when the form control name doesn't
conform with Javascript valid identifier rules. Imagine you have a set
of radioboxes with names adjusted for PHP server-side pre-processing,
so something like <input type="radio" name="radio[0]">, "radio[1]"
etc. Obviously by using the shortcut form
document.forms['myForm'].radio[0] you'll get runtime errors. At the
same time the fully qualified notation will work:
document.forms['myForm'].elements['radio[0]']
Jun 27 '08 #3
VK wrote:
On May 25, 3:12 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
><form name="myForm" action="..."<p> <input type="text"
name="myElem"> </p</form>

As far as I was able to get the following is the standard way of
accessing HTML form elements:

document.for ms['myForm'].elements['myElem']

But I have also seen the following:

document.for ms['myForm'].myElem

The latter is a shortcut accessor to the same element.
It sa reference to the same element _object_, if that.
Most of the time the shortcut form can be used to preserve your keyboard
and your finger tips :-) It is not the case when the form control name
doesn't conform with Javascript valid identifier rules.
Wrong. The proprietary referencing allows

document.forms['myForm']["myElem[]"]

as well.

The reason for using the standards-compliant approach over the proprietary
one is that the latter is the *proprietary* one. Proprietary approaches
should be avoided, and should only serve as a fallback for
standards-compliant approaches because, theoretically, by definition they
could break any minute the code is exposed to another, previously unknown,
user agent.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jun 27 '08 #4
Sun, 25 May 2008 07:51:22 -0700 (PDT), /VK/:
On May 25, 3:12 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
>document.for ms['myForm'].elements['myElem']

But I have also seen the following:

document.for ms['myForm'].myElem

The latter is a shortcut accessor to the same element. Most of the
time the shortcut form can be used to preserve your keyboard and your
finger tips :-)
Yes, it seems to save typing but I haven't found it described in the
ECMAScript language binding [1] of the DOM Level 2 HTML
specification, so I've thought it is just deprecated as Thomas Lahn
suggested in another reply. Having said that my question could be
stated better as "should the second form of access not be used in
newly written scripts?".

[1] http://www.w3.org/TR/DOM-Level-2-HTM...t-binding.html

--
Stanimir
Jun 27 '08 #5
VK
On May 25, 7:01 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
The reason for using the standards-compliant approach over the proprietary
one is that the latter is the *proprietary* one.
???

forms[index] or forms["formName"] exposes an object with properties
representing form elements (a.k.a. controls) in the given form.
Javascript allows to access object property over squared brackets
notation or over dot notation, other words in object foo with property
bar, the bar value can be accessed either
foo["bar"]
or
foo.bar
The latter form is a convenience shortcut of the first one and
acceptable iff the property name corresponds to the Javascript
identifier naming rules. Say if the property named not "bar" but
"class" or "bar[0]" or "#$&%&#*" etc. then only the full form is
usable.

These are basics of the language itself, so naturally they are not
documented over and over again wherever objects are discussed: just
like in a complex analysis math books they don't explain what do +, -
and other basic signs mean before each new formula. Once explained -
works everywhere further unless explicitly spelled otherwise.
Jun 27 '08 #6
VK
On May 25, 7:05 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
Yes, it seems to save typing but I haven't found it described in the
ECMAScript language binding [1]
See my answer to Thomas. Both accessor syntax types are in the
language core, so not explained in each particular application.
Jun 27 '08 #7
Sun, 25 May 2008 08:37:30 -0700 (PDT), /VK/:
On May 25, 7:05 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
>Yes, it seems to save typing but I haven't found it described in the
ECMAScript language binding [1]

See my answer to Thomas. Both accessor syntax types are in the
language core, so not explained in each particular application.
I understand if object.property Name works, object["propertyNa me"]
will also work equally but could you point me where in the DOM Level
2 HTML specification (and its ECMAScript language binding) it is
stated form elements are exposed as properties of the
HTMLFormElement object?

While these are same:

document.forms["formName"].elemName
document.forms["formName"]["elemName"]

they are different from:

document.forms["formName"].elements["elemName"]

the later being the only thing I've found defined in the standard.

--
Stanimir
Jun 27 '08 #8
Stanimir Stamenkov wrote:
Sun, 25 May 2008 09:22:41 -0700 (PDT), /VK/:
>DOM 0,

This has always been referred to something different vendors have
once implemented but hasn't been standardized later, either because
the standard covers the features in a different way (though a way
the vendors have agreed on), or the features could not be specified
in way all vendors agree on at the time.

http://www.w3.org/TR/DOM-Level-2-HTM...dt-DOM-Level-0
What you and I have cited states that DOM Level 2 HTML specifies features
that are also found in "DOM Level 0". It is therefore obvious nonsense to
state that "DOM Level 0" it has not been standardized later; some parts of
it have been, and HTMLDocument::f orms is one good example of that.

However, as you have observed, the standards-compliant referencing uses
specific collections and control names as as their property/item names, not
only control names, for the referencing.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #9
VK wrote:
On May 25, 10:17 pm, Stanimir Stamenkov <s7a...@netscap e.netwrote:
>If you never read any specification (being standard or not)

I didn't say that: I said that I never bothered to read W3C specs as I
see very low practical value in that.
And therefore you think that you of all people are in a position
to tell the difference between standards-compliant or proprietary,
and to make recommendations in that matter.

You're right. And the moon consists of green cheese. [psf 4.17]
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4549
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the 'Save as Incomplete' button is Clicked the form will be going to the "SaveAsincomplete.asp" without validation of the fields. And when the 'save as complete' is clicked certain fileds are to be validated and by the function return value, if false...
3
4681
by: Don | last post by:
I can successfully force submission of a <form> using "document.formname.submit()". But, the submission doesn't appear to occur when used with Netscape. Anybody know why this is happening, and what I can do to get around this? Thanks, Don -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World!
2
2815
by: Scott | last post by:
I need to write a function that copies variables to fields. I've used an array and loop because it's neater than writing a similar sentence out 10 times. var myString = new String("id,callername,address,phone,phoneb,email,sqft,source,action,status"); var myFields = myString.split(','); //myValues is an array of values passed to the function var myValues =
10
1772
by: Data Guy | last post by:
In my approach to validation for widgets, i write javascript functions. At the end of the document, inside the form, i invoke the function as <FORM NAME="testit"> <INPUT TYPE="TEXT" VALUE="2" NAME="_widge1"> <INPUT TYPE="BUTTON" VALUE="Edit" onclick="valfunc(this.form);"> </FORM> where
7
2960
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+ produciton environment ( not my choice, but when is it ever? ). the desired output is that when the end-user selects two radio buttons, one from each 'group', the form / page will open an alert window displaying the values of the radio buttons...
4
2705
by: JV | last post by:
I thought I once saw somewhere that a global variable, "xyz" for example, could be declared and used so that instead of using "document.formname.elementname.value" one could use "xyz.elementname.value" or use "xyz" in place of "document.formname" anytime a reference to a form element was made. Is this actually true or not? I'm going crazy trying to recall something that might not even exist! Thanks.
2
2098
by: kigoobe | last post by:
Well, I'm getting an error. Here is the function, what, according to FF's consolde is generating the error. function citizen3() { if (document.ededfil.nationalite.checked == true) { document.ededfil.pays_origine.checked = true; document.ededfil.pays_origine.disabled = true; document.ededfil.pays_origine.disabled = true; document.ededfil.pays_origine.disabled = true; } else if...
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3276
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.