473,405 Members | 2,373 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,405 software developers and data experts.

What is better, document.forms or getElementById?

Hi,

I would like to know if is better to use document.forms to detect forms
or getElementById.

Thanks

Dec 21 '06 #1
2 2937
Marcos José Setim wrote:
I would like to know if is better to use document.forms to detect forms
or getElementById.
document.forms.formName or document.forms['formName'] has much better
support in older browsers, compared to
document.getElementById('formId'). On the other hand it depends on what
you want to do with your script, if you want to e.g. cloneNode,
removeChild, appendChild stuff in the form then document.forms might
access the form element object in older browsers while the remaining
functionality is not supported at all so you have no advantage using
document.forms.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 21 '06 #2
Marcos José Setim said the following on 12/21/2006 10:32 AM:
Hi,

I would like to know if is better to use document.forms to detect forms
or getElementById.
First, you have to give a definition for "better".

Backwards compatibility: document.forms

Modernization: document.getElementById

Speed: That depends - directly - on two things:

1) The browser in use.
2) The HTML the browser is looking through.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '06 #3

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

Similar topics

3
by: Rosinger | last post by:
Hi all, What is the preferred in term of browser copatability to get a reference to an element in the document in JavaScript? I am not sure about when to use document.all or document.layers or...
5
by: yoelgold | last post by:
hi can someone please tell me what "document.MM_sr" is. I tried searching for a explanation on the web but cant find anything. What does MM_sr represent? and where can i get documentation on it. ...
1
by: Colin McNaught | last post by:
I'm sure this counts as a newbie question: Take the html expression <a name="thisname" href="newpage.html">GoToIt</a> Inside the <a> tag, 'this' can be used in javascript to refer to the url the...
8
by: bradwiseathome | last post by:
I have code that works in IE 6 but does not work in FireFox 1.0.2, how can I change it so it works in both browsers? <html> <head> <script language="JavaScript" type="text/JavaScript">...
5
by: windandwaves | last post by:
Hi Folk I found the following function somewhere on the web. I am not sure how it works, but I am sure that it is very useful: function getObj(name) { if (document.getElementById){...
6
by: Leszek | last post by:
Hi. I wrote a script: function zmiana(ile){ while(document.getElementById('accomp').childNodes.length>1){ ostatni=document.getElementById('document.dane.accomp').lastChild;...
4
by: brian | last post by:
i broke down where i think the problems areas would be. any help would be greatly appreciated. where the file is called <script type="text/javascript" src="k.js"> </script> the beginning...
3
by: =?iso-8859-1?q?Marcos_Jos=E9_Setim?= | last post by:
Hi, I would like to know if is better to use document.forms to detect forms or getElementById. Thanks
6
by: therig | last post by:
I'm having issues, I've spent many hours searching and I'm a noob at javascript, any help will be greatly appreciated. I keep getting the following error: Error: document.forms.sec11_A has no...
5
by: ankit1999 | last post by:
I have a problem, everytime i'm run this page http://click2travel.in/index.php i get the this error,,,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.