View Full Version : Help with: Switch Content Script

09-06-2006, 03:19 PM
1) Script Title: Switch Content Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent.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">')

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


<h1 onclick expand div1...></h1>
<div id=1>
<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.


09-07-2006, 07:32 AM
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:

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)
return temparray

Just add the part in red to your version, it will make these 'i's local variables.

09-07-2006, 09:35 AM
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=http%3A%2F%2Fwww.tsrealms.com%2Fdictionary.shtml )