the coding room

a place for coder talks

IE bug?

I don’t know about you folks, but I have a little function I call to get an element by its id and it goes something like this

function getObj( pID ) {
    if( util.docRoot.getElementById )
    {
        return util.docRoot.getElementById( pID );
    }
    else if( util.docRoot.all )
    {
        return util.docRoot.all[pID];
    }

    return false;
}

For example, we have two <input> fields as such

<input type=”text” id=”shakeit” name=”shakethis” value=”valueA” />

<input type=”text” id=”shakethis” value=”valueB” />

Well, in Firefox, when I do

var someElement = getObj( ’someID’ );

the someElement contains the element with ID equal to “shakethis”, as expected.
In Internet Explorer though, someElement contains the first occurence of “shakethis”
even if it matches the name of the <input>.

Which, in the above example, means that if we were to print someElement.value this would be equal to “valueB” in Firefox
and “valueA” in IE.

Weird bug or just me being totally ignorant??

Or, as someone would say, is it a bug or a feature??

Posted in HTML, Web Development, Javascript |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.