"Object Required" error in IE for javascript that works fine in FF
The page I am working on has a tabbed interface which works fine using FF but when viewed from IE I receive an "object required" error message at the SetCurrent("Users Table") call.
My page has FindCurrent() being called at page load which, if it can match the page title up with a specific list it calls a 2nd function which changes the id on a specific list item so that it shows up as "Selected".
Does anybody have an idea as to what I am doing wrong?
Code:
function SetCurrent(title)
{
// Find all list items on the page
var oSubjects = document.getElementsByTagName("li");
// Cycle through the list items
for (var i = 0; i < oSubjects.length; i++)
{
var oSubject = oSubjects.item(i);
var sID = oSubject.getElementsByTagName("span");
// Check the text displayed on them to see if it matches the title passed in
if ( sID.item(0).innerHTML == title ) {
oSubject.id="current"; // Sets the list item as the "Current" one.
}
}
}
function FindCurrent()
{
var titleElement = document.getElementsByTagName("title")[0];
// Matching the TITLE of the page up. If it is found then send in the text displayed on the Tab which is "current"
if ( titleElement.firstChild.data == "User Table" ) {
SetCurrent("Users Table");
} else if ( titleElement.firstChild.data == "Table List" ) {
SetCurrent("View Tables");
} else if ( titleElement.firstChild.data == "Event Table" ) {
SetCurrent("Event Table");
} else if ( titleElement.firstChild.data == "Inventory Table" ) {
SetCurrent("Inventory Table");
}
}
Last edited by Ryland; June 17th, 2008 at 02:10 PM.
IE loves to through the "Object required" error because it is not completely DOM compliant. That is why I suggest checking for the DOM element before you apply anything to it, or attempt to read it.
For example, you might want to try the following instead. There might be other parts in your code that need this same implementation.
Code:
if (titleElement.firstChild) {
if (titleElement.firstChild.data == "User Table") {
...
}
}
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Thanks, that did get rid of the error message but then the code to set which is the "current" tab doesn't get executed. Is this an IE issue that there isn't a work around for?
Bookmarks