473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Accessing form control elements

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/doctorunc...e7Section.html

Jul 20 '05 #1
1 4050
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" <dr*******@hotREMOVEmail.com> wrote in message
news:bg*********@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/doctorunc...e7Section.html

Jul 20 '05 #2

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

Similar topics

3
by: Martien van Wanrooij | last post by:
I am working on a site with some pages that all have a form that starts with a group of radiobuttons. By default none of the buttons is checked. Before submitting the form there is a validation...
4
by: Paweł | last post by:
We can access the Nth element in the first form by document.forms.elements imagine that theres function like <INPUT TYPE=TEXT" onclick="somefunction(this)"> and... we have function...
5
by: Craig Anderson | last post by:
Can anyone tell me the best way to access a hidden object in a form? I could use a hard-coded index to the elements of the form, but it's too easy to add something before the hidden object and mess...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
1
by: Suhail A, Salman | last post by:
Dear All, I placed a HtmlSelect control on a web page and set it to "Run at Server", the objective of this HtmlSelect control is that the client adds all his accounts to a text box, and...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
2
by: lasher168 | last post by:
Hi, I have a problem which I have been on pondering all day and wasting time !!! I have a javascript call which looks like this <td width="50%" class="inputLabel"><span...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
3
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.