PDA

View Full Version : Switch Content Script IE - Help



wbwillson
02-10-2005, 04:30 PM
Hi,

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


http://www.dynamicdrive.com/dynamicindex17/switchcontent.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:


<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:


<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

eau femme
02-11-2005, 12:58 AM
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.

wbwillson
02-11-2005, 09:35 AM
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?


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()
}
}
}

wbwillson
02-11-2005, 10:01 AM
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