Accessing form control elements

D

DU

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
 
L

lallous

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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top