PDA

View Full Version : Slide down menu, help



jonesyR
09-25-2010, 02:26 PM
1) Script Title: Slashdot

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

3) Describe problem:



Hi, im pretty new to this stuff. I am from Northern Ireland, and im doing my Alevel website project on Microsoft Frontpage.

I decided i'd get ahead a little and have a sort of drop down menu.
Anyway i got it all sorted and it was all working smoothly, until it suddenly just stopped working....

Anyway here's where i got the code from...

--
http://www.dynamicdrive.com/dynamicindex1/slashdot.htm
--

However, now when i go to preview it, it comes up with these two errors..

http://i56.tinypic.com/2cncilc.png

&

http://i53.tinypic.com/9zm6qe.png


......

This is what they look like atm on my navigation page with edited links...

http://i56.tinypic.com/jk9kyo.png

..However, when i click on the bars, they do not collapse or expand, this is what i need to resolve.

The following snippet is from the code for my navigation page..

*******


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 3</title>
<base target="main">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Slashdot's Menu</title>
<link rel="stylesheet" type="text/css" href="sdmenu.css" />
<script type="text/javascript" src="sdmenu.js">

</script>
<script type="text/javascript">
// <![CDATA[
var myMenu;
window.onload = function() {
myMenu = new SDMenu("my_menu");
myMenu.init();
};
// ]]>
</script>


</head>

<body>




<div style="float: left" id="my_menu" class="sdmenu">


<div>
<span>Components</span>
<a target="main" href="Graphics.htm">Graphics</a>
<a target="main" href="Processors.htm">Processors</a>
<a target="main" href="Memory.htm">Memory</a>
<a target="main" href="Motherboards.htm">Motherboards</a>


</div>

<div>
<span>Storage</span>
<a target="main" href="Internal & External HDD.htm">Internal &amp; External
HDD</a>
<a target="main" href="Memory Cards.htm">Memory Cards</a>
<a target="main" href="USB Flash.htm">USB Flash</a>
</div>

<div>
<span>Monitors</span>
<a target="main" href="LCD.htm">LCD</a>
<a target="main" href="Plasma.htm">Plasma</a>
<a target="main" href="CRT.htm">CRT</a>

</div>

<div>
<span>Peripherals</span>
<a target="main" href="Keyboards & Mice.htm">Keyboards &amp; Mice</a>
<a target="main" href="Speakers.htm">Speakers</a>
<a target="main" href="Headsets.htm">Headsets</a>

</div>

<div>
<span>Laptops</span>
<a target="main" href="Notebook.htm">Notebooks</a>
<a target="main" href="Netbook.htm">Netbooks</a>

</div>


</body>

</html>

Also...below is what is within sdmenu.js


function SDMenu(id) {
if (!document.getElementById || !document.getElementsByTagName)
return false;
this.menu = document.getElementById(id);
this.submenus = this.menu.getElementsByTagName("div");
this.remember = true;
this.speed = 3;
this.markCurrent = true;
this.oneSmOnly = false;
}
SDMenu.prototype.init = function() {
var mainInstance = this;
for (var i = 0; i < this.submenus.length; i++)
this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
mainInstance.toggleMenu(this.parentNode);
};
if (this.markCurrent) {
var links = this.menu.getElementsByTagName("a");
for (var i = 0; i < links.length; i++)
if (links[i].href == document.location.href) {
links[i].className = "current";
break;
}
}
if (this.remember) {
var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
var match = regex.exec(document.cookie);
if (match) {
var states = match[1].split("");
for (var i = 0; i < states.length; i++)
this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
}
}
};
SDMenu.prototype.toggleMenu = function(submenu) {
if (submenu.className == "collapsed")
this.expandMenu(submenu);
else
this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
var links = submenu.getElementsByTagName("a");
for (var i = 0; i < links.length; i++)
fullHeight += links[i].offsetHeight;
var moveBy = Math.round(this.speed * links.length);

var mainInstance = this;
var intId = setInterval(function() {
var curHeight = submenu.offsetHeight;
var newHeight = curHeight + moveBy;
if (newHeight < fullHeight)
submenu.style.height = newHeight + "px";
else {
clearInterval(intId);
submenu.style.height = "";
submenu.className = "";
mainInstance.memorize();
}
}, 30);
this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
var mainInstance = this;
var intId = setInterval(function() {
var curHeight = submenu.offsetHeight;
var newHeight = curHeight - moveBy;
if (newHeight > minHeight)
submenu.style.height = newHeight + "px";
else {
clearInterval(intId);
submenu.style.height = "";
submenu.className = "collapsed";
mainInstance.memorize();
}
}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
if (this.oneSmOnly) {
for (var i = 0; i < this.submenus.length; i++)
if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
this.collapseMenu(this.submenus[i]);
}
};
SDMenu.prototype.expandAll = function() {
var oldOneSmOnly = this.oneSmOnly;
this.oneSmOnly = false;
for (var i = 0; i < this.submenus.length; i++)
if (this.submenus[i].className == "collapsed")
this.expandMenu(this.submenus[i]);
this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
for (var i = 0; i < this.submenus.length; i++)
if (this.submenus[i].className != "collapsed")
this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
if (this.remember) {
var states = new Array();
for (var i = 0; i < this.submenus.length; i++)
states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
var d = new Date();
d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
}
};

********

If someone can please tell me why they are no longer expanding or collapsing id be hugely grateful...also when it refers to the errors about SDmenu etc, it cannot because i have edited with a bad syntax, as i have pasted the default extracted original copy.