thesmart1
02-06-2007, 11:30 PM
I'm working on a drop-down menu script, but it's not positioning the menus right (actually, not at all). I have it set up to get the left position and bottom position (by adding the top and height) with getElementById(), then make these values the left and top positions of the menu, respectively. Is it not possible to define a variable with getElementById()?
I tried two scripts, one slightly different from the other:
Script 1:
function showmenu(showmenunum){
menubaritemnum="menubaritem"+showmenunum;
menunum="menu"+showmenunum;
menubaritempostop=document.getElementById(menubaritemnum).style.top;
menubaritemheight=document.getElementById(menubaritemnum).style.height;
menuposleft=document.getElementById(menubaritemnum).style.left;
menupostop=menubaritempostop+menubaritemheight;
document.getElementById(menunum).style.position="absolute";
document.getElementById(menunum).style.top=menupostop;
document.getElementById(menunum).style.left=menuposleft;
document.getElementById(menunum).style.visibility="visible"
}
Script 2:
function showmenu(showmenunum){
menubaritemnum="menubaritem"+showmenunum;
menunum="menu"+showmenunum;
menubaritem=document.getElementById(menubaritemnum);
menuposleft=menubaritem.style.left;
menupostop=menubaritem.style.top+menubaritem.style.height;
document.getElementById(menunum).style.position="absolute";
document.getElementById(menunum).style.top=menupostop;
document.getElementById(menunum).style.left=menuposleft;
document.getElementById(menunum).style.visibility="visible"
}
A menu bar item is the name of the menu (what you mouseover, like File, Edit, etc).
I tried two scripts, one slightly different from the other:
Script 1:
function showmenu(showmenunum){
menubaritemnum="menubaritem"+showmenunum;
menunum="menu"+showmenunum;
menubaritempostop=document.getElementById(menubaritemnum).style.top;
menubaritemheight=document.getElementById(menubaritemnum).style.height;
menuposleft=document.getElementById(menubaritemnum).style.left;
menupostop=menubaritempostop+menubaritemheight;
document.getElementById(menunum).style.position="absolute";
document.getElementById(menunum).style.top=menupostop;
document.getElementById(menunum).style.left=menuposleft;
document.getElementById(menunum).style.visibility="visible"
}
Script 2:
function showmenu(showmenunum){
menubaritemnum="menubaritem"+showmenunum;
menunum="menu"+showmenunum;
menubaritem=document.getElementById(menubaritemnum);
menuposleft=menubaritem.style.left;
menupostop=menubaritem.style.top+menubaritem.style.height;
document.getElementById(menunum).style.position="absolute";
document.getElementById(menunum).style.top=menupostop;
document.getElementById(menunum).style.left=menuposleft;
document.getElementById(menunum).style.visibility="visible"
}
A menu bar item is the name of the menu (what you mouseover, like File, Edit, etc).