Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Object error - IE only

    Hi,

    I'm getting this error: "error: object required". This only happens in IE. Code works fine in FF w/ no errors. The error occurs when I click on one of the links, which are used to hide/show elements. Here is the Javascript:

    <script language="javascript" type="text/javascript">

    function startList() {
    if (!document.getElementById) return false;
    if (!document.getElementById("campus_list")) return false;
    var campuslist = document.getElementById("campus_list");
    var links = campuslist.getElementsByTagName("a");
    for(var i=0; i<links.length; i++) {
    links[i].onclick = function() {
    var campus = this.getAttribute("class");
    displayCampus(campus);
    }
    }
    }

    function displayCampus (campus) {
    if (!document.getElementById("campus_details")) return false;
    var campusdetails = document.getElementById("campus_details");
    var campuslist = campusdetails.getElementsByTagName("ul");
    for(var i=0; i<campuslist.length; i++) {
    campuslist[i].style.display = "none";
    }
    var whichcampus = campus+"_campus";
    var showcampus = document.getElementById(whichcampus);
    showcampus.style.display = "block";
    }

    window.onload=startList;

    </script>

    Any ideas?

    Thanks in advance,
    Jonathansf

  • #2
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Full code please in [code] brackets!
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Full code is posted here:

    http://www.extremecroquet.com/Test/

    Thanks.

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    *Solution* Object error - IE only

    I found the answer in the archive on these boards.

    Posted by liorean:

    ie doesn't handle setAttribute and getAttribute correctly. It treats elm.setAttribute('attribute',value) as elm.attribute=value. Which means:

    1. It breaks if you try to set attributes that are JavaScript keywords or reserved keywords such as for, class etc.
    2. It's case sensitive for HTML, which it shouldn't be.
    3. It doesn't handle attributes containing certain characters.

    Using className you avoid this problem altogether.


    So, in my case:

    var campus = this.getAttribute("class");

    becomes

    var campus = this.className;

    Cheers,
    JP

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Nice to be of assistance
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You may use getAttributeNode() as well. Weird enough (but typically for the IE inconsistency) this time "class" is accepted by IE.

    var campus = this.getAttributeNode("class").nodeValue;
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    LinkBacks (?)


    Posting Permissions

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