If you want to retrieve a reference to an element by it's id attribute, use document.getElementById(inputID);

oikram
—
2010-04-27T16:52:23Z —
#6

So it's preferable to have:

document.getElementById(inputID);

then

document.pedidoOnline[inputID];

?

If so, can I ask why, is it a performance issue or it's related to the fact that if we use the first method we get and id not matter what form we are, hence, we have a more portable code?

Thanks in advance,Márcio

crmalibu
—
2010-04-27T18:03:30Z —
#7

I must have been mistaken, I thought I saw thisdocument[inputID];instead ofdocument.pedidoOnline[inputID];

Still, personally I avoid most of those predefined dom collections, mainly because I don't fully understand what works correctly cross browser, and they really seem to be a minefield because of the way the distinction between names and id's get blurred, all piled into the same structures. I also don't like how sometimes you get an a single element reference, and sometimes you get a collection if you have multiple elements that happen to share the same identifier as a name and id.

I lean towards using the dom methods to get at stuff. The behavior is more consistant and intuitive imo. Again, this is because I simply don't understand in enough detail how some of those predefined collections work in the various browsers and versions, so I just avoid it.

oikram
—
2010-04-27T18:42:33Z —
#8

I see. Having some (little experience) with css cross browser issues, I cannot even imagine dealing with 3 or for times more due to DOM levels and interpretations on different browsers.

Can I please ask one last question, given the code above (the initial one) how would your re-write it, using DOM methods?

Thanks again,Márcio

ScallioXTX
—
2010-04-27T18:45:10Z —
#9

Take the function of oikram and replace document.pedidoOnline[inputID] by document.getElementById(inputID)

oikram
—
2010-04-27T18:52:21Z —
#10

ScallioXTX said:

Take the function of oikram and replace document.pedidoOnline[inputID] by document.getElementById(inputID)

So, both lines on the liink "function of oikram" are indeed representing the same thing? The only difference is that one is traveling along the DOM tree structure and the other is using a DOM method.