mrtanooki
09-10-2004, 05:25 PM
I'm brand new at javascript programming and i'm making a script for a company website that displays a menu.
What i want to happen is when a user puts the mouse curser over menu item a submenu drops down, and when the mouse moves to a different menu item the previous submenu retracts and the other submenu drops down.
The way i'm doing it right now works perfectly in Mozilla FireFox, but does not work at all in Internet Explorer 6:
linkelement = document.createElement("a");
linkelement.setAttribute("onMouseOver","expand()");
Is there an (easy) alternative way that i can apply an onMouseOver action that works for IE as well as Mozilla?
Here is the full (temporary) code:
<script type="text/javascript">
var idgroups = new Array();
var menulist = document.createElement("ul");
var submenulist;
var menulist;
var menuitem;
var linkelement;
var sublinkelement;
var menuelement = document.getElementById("menu");
var menuitemname;
var submenuitemname;
var menuitemvalue;
var menu = new Array();
var menuvars = new Array();
var submenu = new Array();
var subvars;
var menu = ["One","Two","Three"];
var menuvars = ["assassinate","your","parents"];
var submenu = [new Array("HEH","heh","hEh"),new Array("Rofl","Lmao","LoL"),new Array("I","like","poop")];
var subvars = [new Array("...","...","..."),new Array("...","...","..."),new Array("...","...","...")];
function buildmenu() {
menuelement = document.getElementById("menu");
for (menulen=0; menulen!=menu.length; menulen++) {
// here we create teh menu items
menuitem = document.createElement("li");
linkelement = document.createElement("a");
linkelement.setAttribute("href",menuvars[menulen]+"/index.phtml");
linkelement.setAttribute("onMouseOver","expand()");
menuitemname = document.createTextNode(menu[menulen]);
linkelement.appendChild(menuitemname);
menuitem.appendChild(linkelement);
// this is whurr we make teh submenu items
submenulist = document.createElement("ul");
for (submenulen=0; submenulen!=submenu[menulen].length; submenulen++) {
submenuitem = document.createElement("li");
sublinkelement = document.createElement("a");
sublinkelement.setAttribute("href",menuvars[menulen]+"/"+subvars[menulen][submenulen]+".phtml");
submenuitemname = document.createTextNode(submenu[menulen][submenulen]);
sublinkelement.appendChild(submenuitemname);
submenuitem.appendChild(sublinkelement);
submenulist.appendChild(submenuitem);
menuitem.appendChild(submenulist);
}
menulist.appendChild(menuitem);
}
menuelement.appendChild(menulist);
}
function expand() {
document.write("I hate you.");
}
</script>
<body onload="buildmenu()">
<div id="menu">
</div>
</body>
Please just focus at the question on hand, i realize my code isn't very well done. Remember I just started programming javascript recently.
What i want to happen is when a user puts the mouse curser over menu item a submenu drops down, and when the mouse moves to a different menu item the previous submenu retracts and the other submenu drops down.
The way i'm doing it right now works perfectly in Mozilla FireFox, but does not work at all in Internet Explorer 6:
linkelement = document.createElement("a");
linkelement.setAttribute("onMouseOver","expand()");
Is there an (easy) alternative way that i can apply an onMouseOver action that works for IE as well as Mozilla?
Here is the full (temporary) code:
<script type="text/javascript">
var idgroups = new Array();
var menulist = document.createElement("ul");
var submenulist;
var menulist;
var menuitem;
var linkelement;
var sublinkelement;
var menuelement = document.getElementById("menu");
var menuitemname;
var submenuitemname;
var menuitemvalue;
var menu = new Array();
var menuvars = new Array();
var submenu = new Array();
var subvars;
var menu = ["One","Two","Three"];
var menuvars = ["assassinate","your","parents"];
var submenu = [new Array("HEH","heh","hEh"),new Array("Rofl","Lmao","LoL"),new Array("I","like","poop")];
var subvars = [new Array("...","...","..."),new Array("...","...","..."),new Array("...","...","...")];
function buildmenu() {
menuelement = document.getElementById("menu");
for (menulen=0; menulen!=menu.length; menulen++) {
// here we create teh menu items
menuitem = document.createElement("li");
linkelement = document.createElement("a");
linkelement.setAttribute("href",menuvars[menulen]+"/index.phtml");
linkelement.setAttribute("onMouseOver","expand()");
menuitemname = document.createTextNode(menu[menulen]);
linkelement.appendChild(menuitemname);
menuitem.appendChild(linkelement);
// this is whurr we make teh submenu items
submenulist = document.createElement("ul");
for (submenulen=0; submenulen!=submenu[menulen].length; submenulen++) {
submenuitem = document.createElement("li");
sublinkelement = document.createElement("a");
sublinkelement.setAttribute("href",menuvars[menulen]+"/"+subvars[menulen][submenulen]+".phtml");
submenuitemname = document.createTextNode(submenu[menulen][submenulen]);
sublinkelement.appendChild(submenuitemname);
submenuitem.appendChild(sublinkelement);
submenulist.appendChild(submenuitem);
menuitem.appendChild(submenulist);
}
menulist.appendChild(menuitem);
}
menuelement.appendChild(menulist);
}
function expand() {
document.write("I hate you.");
}
</script>
<body onload="buildmenu()">
<div id="menu">
</div>
</body>
Please just focus at the question on hand, i realize my code isn't very well done. Remember I just started programming javascript recently.