This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes why document.getElementById work with form elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic
Author

why document.getElementById work with form elements

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I wanted to know if document.getElementById works while accessing form elements.
I tried doing this just for testing purposes

This code doesnt work


but this does


Why doesnt document.getElementByid work with form objects.it works with all non form HTML objects..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60767
    
  65

Of course it works with form elements. It works with any element in the DOM.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Bear Bibeault wrote:Of course it works with form elements. It works with any element in the DOM.


Hmm.. could you suggest what I might be doing wrong here ??



and the function is
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60767
    
  65

Looks like this is the same issue as your other post. Let's continue any further discussion there.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why document.getElementById work with form elements
 
Similar Threads
How to define focus() method in JS
does firefox have a problem with .setAttribute ?
how to access values in session from javascript
My form submit is called twice