...

View Full Version : Menu Script Not Positioning Menus



thesmart1
02-07-2007, 12:30 AM
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).

thesmart1
02-07-2007, 03:09 AM
I tested it by adding an alert() to the function to return the left position of the current menu bar item, but it was blank. I guess getElementById can't return values (or I'm doing something wrong). Is there another way?

vwphillips
02-07-2007, 08:33 AM
home brew menus are somthing one should avoid
but may be able a look if you post the page or link to a page with the scipt and HTML.

thesmart1
02-08-2007, 02:44 AM
Sorry about taking so long, I was finishing some basic CSS because it was just a rough page before.

http://random.pehjota.com/

thesmart1
02-10-2007, 03:49 AM
Okay, I positioned the menus with CSS instead, which is what i was trying to avoid in the first place. But now for some reason, the links in the menus aren't working. (same URL as above)

thesmart1
02-11-2007, 11:00 PM
I just took the menu content out of the JavaScript and used a PHP includes function instead. So now it works perfectly. First time I ever used PHP, and I now love it lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum