![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
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? |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
On May 25, 3:12 pm, Stanimir Stamenkov <s7a... (AT) netscape (DOT) net> wrote: 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. |
#5
| |||
| |||
|
|
On May 25, 3:12 pm, Stanimir Stamenkov <s7a... (AT) netscape (DOT) net> wrote: 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 :-) |
#6
| |||
| |||
|
|
The reason for using the standards-compliant approach over the proprietary one is that the latter is the *proprietary* one. |
#7
| |||
| |||
|
|
Yes, it seems to save typing but I haven't found it described in the ECMAScript language binding [1] |
#8
| |||
| |||
|
|
On May 25, 7:05 pm, Stanimir Stamenkov <s7a... (AT) netscape (DOT) net> wrote: 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. |
#9
| |||
| |||
|
|
The reason for using the standards-compliant approach over the proprietary one is that the latter is the *proprietary* one. |
#10
| |||
| |||
|
|
Sun, 25 May 2008 08:37:30 -0700 (PDT), /VK/: On May 25, 7:05 pm, Stanimir Stamenkov <s7a... (AT) netscape (DOT) net> wrote: 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.propertyName works, object["propertyName"] 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? |
![]() |
| Thread Tools | |
| Display Modes | |
| |