473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2948
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
2390
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
8886
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
1758
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
1811
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
1644
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
6303
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
1561
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
377
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
3355
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
3993
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
7199
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
7074
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
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
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...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
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,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.