Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Menu Script Not Positioning Menus

    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:
    Code:
    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:
    Code:
    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).

  • #2
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    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?

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    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.
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #4
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Sorry about taking so long, I was finishing some basic CSS because it was just a rough page before.

    http://random.pehjota.com/

  • #5
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    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)

  • #6
    Regular Coder thesmart1's Avatar
    Join Date
    Dec 2005
    Posts
    369
    Thanks
    7
    Thanked 3 Times in 3 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •