f



Accessing form control elements

Assuming you have a typical form built in this manner:

<form action="...">
<p><input id="idInputText" name="nameInputText" type="text" size="20"></p>
<p><input id="idCheckbox" name="nameCheckbox">optional</p>
<p><input id="idRadio1" name="nameRadio">yes<input id="idRadio2" 
name="nameRadio">no</p>
<p><select id="idSelect" name="nameSelect"><option 
value="a">a</option><option value="b">b</option><option 
value="c">c</option></select></p>
</form>

then what would be the most efficient way of referencing these form 
control elements? With the name attribute or with the id attribute?

With
document.forms[0].nameInputText
or with
document.getElementById("idInputText")?
Same thing with other form control elements. Id or name? Which is the 
most efficient?

How can you measure this for comparison purposes?

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html

0
DU
8/6/2003 11:42:57 AM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

1 Replies
381 Views

Similar Articles

[PageSpeed] 53

For compatibility reasons accessing via form.ElementName is better.
> document.forms[0].nameInputText
imho, this is better especially if you don't want to do more than form
element management. (reading/writing value).

Elias

"DU" <drunclear@hotREMOVEmail.com> wrote in message
news:bgqpkd$u9$1@news.eusc.inter.net...
>
> Assuming you have a typical form built in this manner:
>
> <form action="...">
> <p><input id="idInputText" name="nameInputText" type="text" size="20"></p>
> <p><input id="idCheckbox" name="nameCheckbox">optional</p>
> <p><input id="idRadio1" name="nameRadio">yes<input id="idRadio2"
> name="nameRadio">no</p>
> <p><select id="idSelect" name="nameSelect"><option
> value="a">a</option><option value="b">b</option><option
> value="c">c</option></select></p>
> </form>
>
> then what would be the most efficient way of referencing these form
> control elements? With the name attribute or with the id attribute?
>
> With
> document.forms[0].nameInputText
> or with
> document.getElementById("idInputText")?
> Same thing with other form control elements. Id or name? Which is the
> most efficient?
>
> How can you measure this for comparison purposes?
>
> DU
> --
> Javascript and Browser bugs:
> http://www10.brinkster.com/doctorunclear/
> - Resources, help and tips for Netscape 7.x users and Composer
> - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
> http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html


0
lallous
8/6/2003 12:37:21 PM
Reply: