Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the different of command

 
Nakata kokuyo
Ranch Hand
Posts: 467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic