Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Drop Menu Issue 2

Status
Not open for further replies.

bigpapaguru

Instructor
Jan 26, 2005
4
US
I have a page with two different navigation elements one that is a horizontal drop down on the top of the page, and one that is verticle drop down on the left side of the site.

To make the drop downs I followed the tutorial here
========= MY PROBLEM =========
I named the top drop down "1nav" and the side drop down "2nav"

When I use this script the last getElementById in the script is the only menu that will work in my site. Something seems to cancle out the top function.

If anyone could help it would be much appreciated.

Thanks
Matt

// JavaScript Document

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("1nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes;
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;


startList2 = function() {
if (document.all&&document.getElementById) {
navRoot2 = document.getElementById("2nav");
for (i=0; i<navRoot2.childNodes.length; i++) {
node2 = navRoot2.childNodes;
if (node2.nodeName=="LI") {
node2.onmouseover=function() {
this.className+=" over";
}
node2.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList2;
 
You can only have 1 window.onload (or onload handler in the body tag). To run both these functions onload of the page then put them together in one function and just call that:
Code:
function onloadFunction() {
   startList();
   startList2();
}
window.onload=onloadFuntion;

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
Two suggestions:
[ol]
[li]Remove [tt]window.onload=startList;[/tt]. Replace [tt]window.onload=startList2;[/tt] with this: [tt]window.onload=function() { startList(); startList2(); }[/tt][/li]
[li]Avoid using document.all. There are many other more modern ways of doing browser differentiation.[/li]
[/ol]

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hey guys thanks for you help!

It now works perfectly...
~BPG
 
The site that hosted the picture either doesn't exist anymore or doesn't allow remote linking to images. I've put in a request to tek-tips management to add it as an emoticon and emailed them the image. I got word that they'd add it once it got approval, but they are always busy with stuff for the site that's important, so I'm not gonna bug em too much about a smiley [lol]

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top