Results 1 to 3 of 3

Thread: Help with: Switch Content Script

  1. #1
    Join Date
    Sep 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with: Switch Content Script

    1) Script Title: Switch Content Script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...tchcontent.htm

    3) Describe problem:
    After editing the code to suit my purposes, it no longer works in IE. It's working fine in FF, but in IE, although the pointer changes on mouse over, clicking doesn't expand the block. I uploaded the exact version from the page where I found the script (the link above) and that one worked fine. I just can't figure out why it stopped working..

    Here's exactly what I changed.

    I removed this portion...

    if (document.getElementById){
    document.write('<style type="text/css">')
    document.write('.switchcontent{display:none;}')
    document.write('</style>')
    }

    .. and just put the css in the head. And I changed all mention of .switchcontent to .hide. As for the html, I'm using headers and divs in levels. 2 headers and three divs.

    EXAMPLE:

    <h1 onclick expand div1...></h1>
    <div id=1>
    <div>
    <h2 onclick expand div2></h2>
    <div id=2>Content</div></div></div>

    As I said, this all works fine and dandy on FF, but IE doesn't even open the first level. Here's a link to the page I'm using it on so you can see the source code. Just let me know if you need me to copy/paste the javascript.

    http://www.tsrealms.com/dictionary.shtml
    Last edited by thePraeotirna; 09-06-2006 at 03:43 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't know if you changed this or if it was sloppy coding to begin with but, this function is the one throwing the error because the <div id="i"> has been defined globally as assigned to the variable 'i' (this only happens in IE where the document.all object can be assumed, even when not written out) as a page element and cannot be used here in this manner:

    Code:
    function getElementbyClass(rootobj, classname){
    var temparray=new Array()
    var inc=0
    var rootlength=rootobj.length
    for (var i=0; i<rootlength; i++){
    if (rootobj[i].className==classname)
    temparray[inc++]=rootobj[i]
    }
    return temparray
    }
    Just add the part in red to your version, it will make these 'i's local variables.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah. Thank you so much. And yea, that was there to begin with. Someone should definitely let the creator know so they can edit it. Either that or put it in the documentation somewhere.

    I actually had another issue, although I don't know if this really counts in this forum. I'm trying to get the page I'm using the script on to validate as xhtml, and I keep getting errors based on the ;'s and <'s. Having had a look at my code, is there some kind of syntax error in the guys code? Or is this just one of those things that probably can't be validated?

    ( Here's the errors I'm getting. http://validator.w3.org/check?uri=ht...ctionary.shtml )
    Last edited by thePraeotirna; 09-07-2006 at 11:08 AM.

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
  •