Javascript

Questions and Answers : Getting started : Javascript
Message board moderation

To post messages, you must log in.

AuthorMessage
Profile Mr. Majestic
Volunteer tester
Avatar

Send message
Joined: 26 Nov 07
Posts: 4752
Credit: 258,845
RAC: 0
United States
Message 723281 - Posted: 8 Mar 2008, 5:46:49 UTC

The following is a javascript code that controls a drop down menu. It does not work, can any one tell me why?
//global variables for timeout
var t=false,current;
function SetupMenu() {
if (!document.getElementsByTagName) return;
items=document.getElementsByTagName("li");
for (i=0; i<items.length; i++) {
if (items[i].className != "menu") continue;
//set up event handelers
thelink=findChild(items[i],"A");
thelink.onmouseover=ShowMenu;
thelink.onmouseout=StartTimer;
//is there a submenu?
if (ul=findChild(items[i],"UL")) {
ul.style.display="none";
for (j=0; j<ul.childNodes.length; j++) {
ul.childNode[j].onmouseover=ResetTimer;
ul.childNodes[j].onmouseout=StartTimer;
}
}
}
}
// Find the first child object of a certain type
function findChild(obj,tag) {
cn =obj.childNodes;
for (k=0; k<cn.length; k++) {
if (cn[k].nodeName==tag) return cn[k];
}
return false;
}
function ShowMenu(e) {
if (!e) var e =window.event;
//which link was the mouse over?
thislink = (e.target) ? e.target: e.srcElement;
ResetTimer();
//hide previous menu, if any
if (current) HideMenu(current);
//we want the li, not the link
/ thislink = thislink.parentNodes;
current=thislink;
//find submenu, if any
ul = findChild(thislink, "UL");
if (!ul) return;
ul.style.display="block";
}
function HideMenu(thelink) {
//find the submenu, if any
ul = findChild(thelink, "UL");
if (!ul) return;
ul.style.display="none";
}
function ResetTimer() {
if (t) window.clearTimeout(t);
}
function StartTimer() {
t = window.setTimeout("HideMenu(current)",200);
}
//set the menu when the page loads
window.onload=SetupMenu;


ID: 723281 · Report as offensive

Questions and Answers : Getting started : Javascript


 
©2024 University of California
 
SETI@home and Astropulse are funded by grants from the National Science Foundation, NASA, and donations from SETI@home volunteers. AstroPulse is funded in part by the NSF through grant AST-0307956.