Results 1 to 4 of 4

Thread: Switch Content Script IE - Help

  1. #1
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Content Script IE - Help

    Hi,

    I'm trying to implement the code for the "Switch Content Script IE" found at:


    http://www.dynamicdrive.com/dynamici...tchcontent.htm

    It all works perfectly until I try to add a New Expandable item. I'm no good with Javascript so I'm pulling my hair trying to figure out why I can't get more than the default 3 items to show up.

    Heres the default code:

    Code:
    <body>
    
    <h3 onClick="expandcontent(this, 'sc1')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>What is JavaScript?</h3>
    <div id="sc1" class="switchcontent">
    JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
    </div>
    
    <h3 onClick="expandcontent(this, 'sc2')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>Difference betwen Java & JavaScript?</h3>
    <div id="sc2" class="switchcontent">
    Java is completely different from JavaScript- the former is a compiled language while the later is a scripting language.
    </div>
    
    <h3 onClick="expandcontent(this, 'sc3')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>What is DHTML?</h3>
    <div id="sc3" class="switchcontent">
    DHTML is the embodiment of a combination of technologies- JavaScript, CSS, and HTML. Through them a new level of interactivity is possible for the end user experience.
    </div>
    All I want to do is add another one (actually several) like:

    Code:
    <h3 onClick="expandcontent(this, 'sc4)" style="cursor:hand; cursor:pointer"><span class="showstate"></span>Item Number 4 </h3>
    <div id="sc4 class="switchcontent">
    This is a Test
    </div>
    </body>
    I thought that all I would need to do was change the ID (i.e., SC3, SC4, etc..) to make it work but it doesn't. Any ideas? Thanks

    I'm not able to point you to my page as it's on a non-internet connected network.

    Bill
    Last edited by wbwillson; 02-10-2005 at 04:33 PM.

  2. #2
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Bill.

    Try looking at the code you posted more closely:

    <h3 onClick=".....(this, 'sc4')" you were missing the closing ' after sc4.

    Also, for the <div id="sc4" missing closing ".

    I hope this helps.

  3. #3
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Eau,

    Thanks for the reply but I was too quick when typing my help request and 'fat-fingered' the example. On my real page I made sure that the quotes were all there. I was thinking that perhaps the 'expandcontent' function is somehow limiting the list to 3?

    Code:
    function expandcontent(curobj, cid){
    var spantags=curobj.getElementsByTagName("SPAN")
    var showstateobj=getElementbyClass(spantags, "showstate")
    if (ccollect.length>0){
    if (collapseprevious=="yes")
    contractcontent(cid)
    document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
    if (showstateobj.length>0){ //if "showstate" span exists in header
    if (collapseprevious=="no")
    showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
    else
    revivestatus()
    }
    }
    }

  4. #4
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've actually solved my own problem...and of course it was a stupid mistake on my part, nothing to do with the script. I had a misplaced </div> tag that was causing all the probems. I appreciate anyone who took the time to look at this. Thanks

    Bill

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
  •