CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    "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.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+)
    Join Date
    May 2002
    Posts
    10,798

    Re: Odd javascript error from IE

    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.

  3. #3
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    Re: Odd javascript error from IE

    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?

  4. #4
    Join Date
    Nov 2005
    Location
    Rhode Island, USA
    Posts
    52

    Re: Odd javascript error from IE

    I found a solution to the problem. I use document.title instead of trying to get the DOM resource for the title.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width