Solved

Javascript: Difference between getElementById and document.forms

Posted on 2008-10-27
3
601 Views
Last Modified: 2013-11-11
What is the difference between document.getElementById() and document.forms[0].element
0
Comment
Question by:karakav
3 Comments
 
LVL 6

Accepted Solution

by:
slinkygn earned 500 total points
ID: 22810886
GetElementById complies with the W3C Level 1 DOM, while the forms[] array does not -- it's Level 0 DOM.  In general, the first is recommended unless you need compatibility with very old browsers.

But beyond that, both will give you a DOM object in return, and so are functionally similar.
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 22810899
Is it not just a different way of getting the same object?

document.forms is part of the DOM specification and so should not be unnecessarily avoided in favour of getElementById, simply use whatever is easiest.
0
 
LVL 4

Author Closing Comment

by:karakav
ID: 31510225
Thanks.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question