This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes the different of command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "the different of command" Watch "the different of command" New topic
Author

the different of command

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
hi, good day , can i know what is the different between four command

1. document.getElementById(myfield).value
2. document.myform.elements(myField).value
3. document.myform(myField).value
4. document.myform.all(myfield).value

thank you
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
1)DOM method to get ID (IE is bad since lets you get name this way, will not work like tht for other browsers)
2)use the form object element array
3)use the form object element array, just referenced another way
4)IE only way (so do not use)

You can also do

document.forms[0]...
or
document.forms["formName"]

instead of

document.formName

Eric
Roy Ivar Moe
Greenhorn

Joined: Jun 22, 2006
Posts: 21
Hey,

Here is an example form:




(1). - This is used to get the value of an element by using its id to reference the element. I.e. in this example 1 will be returned. As long as your element has an id, I would recommend this way.

(2). - The browser maintains a list of all control elements within a form. You can use this list to get the value of an element. I.e. in this example 1 will be returned. You can also use the list index to fetch an element value e.g.
I.e. in this example 1 will be returned. However, the elements list should not be used to fetch elements values, it should instead be used when you need to iterate all the elements of a form e.g. to disable all elements.

(3). - This is used to get the value of an element by using its id or name to reference the element. I.e. in this example 2 will be returned.
I still recommend (1).

(4). - This is used to get the value of an element by using its id or name to reference the element. I.e. in this example 2 will be returned. This method is proprietary to JScript, so I suggest you forget about (4) and use (1) instead.

Hope this helps,

RIM
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 438
thanks for warm reply, jst wondering , as first is not recommended to use, i found most of the ajax application, using getElementById(), am i right ?
 
Don't get me started about those stupid light bulbs.
 
subject: the different of command