/    Sign up×
Community /Pin to ProfileBookmark

Javascript n00b…need menu help

ok, I’m a .Net programmer and I can read and understand Javascript…but to code it from scratch…no dice and no time to learn (in a crunch at work)
I have this menu system that I use on the intranet website…it’s a menu system created by Dreamweaver MX (it works for me so I don’t complain and don’t have time to get something better)
1 problem….the menus open on mouseover….I need the menus to open on mouseclick…..other than that I want them to act the same…disappear when not hovered over and all that jazz….
if I gave you guys the code could someone explain to me the change that I need to make? I’m sure it can’t be that big of a change….
file is at [URL=http://www.livethislife.net/ltl/downloads/mm_menu.js]http://www.livethislife.net/ltl/downloads/mm_menu.js[/URL]

I appreciate any help given on this.

to post a comment
JavaScript

23 Comments(s)

Copy linkTweet thisAlerts:
@XinSep 09.2003 — well, i moved the check-and-show-dropdown codes from the onMenuItemOver function to the onMenuItemAction function, plz see whether it works or not (rename the .txt to .js first).

thx,

[upl-file uuid=90891c76-fd35-40f9-a99a-040260b81d3e size=30kB]mm_menu.txt[/upl-file]
Copy linkTweet thisAlerts:
@PselusauthorSep 10.2003 — oh dear lord...

well thx for your help....but when you uploaded in .txt format it took away all code formatting (look at your text file)

I'm gonna try to find what you did and change it in the origional file.
Copy linkTweet thisAlerts:
@PselusauthorSep 10.2003 — ok....I finally got the code formatted right (opened it in .Net and it formatted it properly then saved from there) and no...that in fact did not stop them opening on mouseover.

:p

here is what the menu code looks like after I build it dynamically through .Net (based on what's in SQL for each user)

[URL=http://www.livethislife.net/ltl/downloads/nav.txt]http://www.livethislife.net/ltl/downloads/nav.txt[/URL]



wow...that's weird...if you don't right click and save it actually takes a text file and (at least in IE 6.0) it builds a web page....even though it's not an extension of a webpage.

anyway...right click and save.
Copy linkTweet thisAlerts:
@XinSep 10.2003 — i think i didn't make it right. one question though, you just want to click to open a menu but still hover to open the sub-menus, or all click to open a menu and its sub-menus?
Copy linkTweet thisAlerts:
@PselusauthorSep 10.2003 — well if possible, click to open menu, hover to open submenu....but if that's difficult (since I'm assuming both menus and submenus are using the same object)....then click to open both at the least

now I've got an odd problem...I renamed my file before trying to use yours....then I tried yours and it did nothing different so I deleted it and renamed my file back....now when you go over an item it no longer highlights the text white and it also does nothing when you click a menu item.....

gotta figure this one out first now....

btw, thx for you help.



*edit*

I downloaded the mm_menu.js I had posted...and that fixed it....
Copy linkTweet thisAlerts:
@XinSep 10.2003 — actually it's easier to do click to open a menu then hover to open its sub-menus.

the image links in the nav page which trigger the menus are not part of the menu codes, they just detect onmouseover and onmouseout to show and hide a menu.

for those links, i moved the onmouseover codes to the href part so that it needs to be clicked to open a menu, i then coded a new js function to check whether the page has a menu shown already and use it for the onmouseover, thus you will click to open a menu, and if the page still has the menu shown, hovering other links will open their menus, if the page has hided the menu, then hovering the links won't do anything.

thx,

[upl-file uuid=5549c6ce-d66c-4e26-ac42-11cf06fa87c3 size=11kB]mm_menu.zip[/upl-file]
Copy linkTweet thisAlerts:
@PselusauthorSep 10.2003 — no thank YOU

now I hope I can impliment this because that nav.txt file I posted is built dynamically when the page loads....I just gotta look at your code and work it into that

once again, thx
Copy linkTweet thisAlerts:
@PselusauthorOct 13.2003 — just wanted to go back and thank you again Xin....code works wonderfully and does exactly what it needs to....you're my hero.
Copy linkTweet thisAlerts:
@XinOct 13.2003 — you are welcome
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — sorry to dig this up and bug you again Xin...but after adding an item to the menu (with a straight copy and paste of my own code) it started erroring. If you have script debugging turned off in IE then the menu still works perfectly...it just shows an error on the bottom of IE...

any idea why? I haven't changed your code at all...but the error happens when you go over the menu...so I think it might still be trying to open onmouseover or something...

the most annoying part is that it still works...but my bosses are dead set on getting rid of it.
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — for anyone else that might help...here is the problem. This code:
[CODE]yxShowMenu(window.mnuSetup,0,20,null,'imgSetup')[/CODE]
errors...

here is the yxShowMenu sub:
[CODE]
var yxMenuShown=false;
function yxShowMenu(menu, x, y, child, imgname) {
if (yxMenuShown) {
MM_showMenu(menu, x, y, child, imgname)
}
}
[/CODE]

and the mm_showMenu sub:
[CODE]
function MM_showMenu(menu, x, y, child, imgname) {
if (!window.mmWroteMenu) return;
MM_clearTimeout();
if (menu) {
var obj = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
x = moveXbySlicePos (x, obj);
y = moveYbySlicePos (y, obj);
}
if (document.layers) {
if (menu) {
var l = menu.menuLayer || menu;
l.top = l.left = 1;
hideActiveMenus();
if (this.visibility) l = this;
window.ActiveMenu = l;
} else {
var l = child;
}
if (!l) return;
for (var i=0; i<l.layers.length; i++) {

if (!l.layers[i].isHilite) l.layers[i].visibility = "inherit";
if (l.layers[i].document.layers.length > 0) MM_showMenu(null, "relative", "relative", l.layers[i]);
}
if (l.parentLayer) {
if (x != "relative") l.parentLayer.left = x || window.pageX || 0;
if (l.parentLayer.left + l.clip.width > window.innerWidth) l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
if (y != "relative") l.parentLayer.top = y || window.pageY || 0;
if (l.parentLayer.isContainer) {
l.Menu.xOffset = window.pageXOffset;
l.Menu.yOffset = window.pageYOffset;
l.parentLayer.clip.width = window.ActiveMenu.clip.width +2;
l.parentLayer.clip.height = window.ActiveMenu.clip.height +2;
if (l.parentLayer.menuContainerBgColor && l.Menu.menuBgOpaque ) l.parentLayer.document.bgColor = l.parentLayer.menuContainerBgColor;
}
}
l.visibility = "inherit";
if (l.Menu) l.Menu.container.visibility = "inherit";
} else if (FIND("menuItem0")) {
var l = menu.menuLayer || menu;
hideActiveMenus();
if (typeof(l) == "string") l = FIND(l);
window.ActiveMenu = l;
var s = l.style;
s.visibility = "inherit";
if (x != "relative") {
s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
s.left = s.pixelLeft + 'px';
}
if (y != "relative") {
s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
s.top = s.pixelTop + 'px';
}
l.Menu.xOffset = document.body.scrollLeft;
l.Menu.yOffset = document.body.scrollTop;
}
if (menu) window.activeMenus[window.activeMenus.length] = l;
MM_clearTimeout();
yxMenuShown=true;
}
[/CODE]


the error I get says object expected on that first line of code I gave.
Copy linkTweet thisAlerts:
@XinDec 23.2003 — could you post the testing URL?

thx.
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — it's an intranet site...

?

and due to non-disclosure agreements there is no way I could share it with you...

what other information could I provide to figure this out?
Copy linkTweet thisAlerts:
@XinDec 23.2003 — a zip of the menu pages and all the js it includes would help.
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — getting it now...

do you have the ability to run an ASP.Net website?

actually I think (considering this is the only thing I'm working on right now) I'll take the time to make a working internet site using these menu's and see how that goes...I'll send you the link when I get it.

because of non-disclosure crap I'd hafta take out a TON of code to zip and give it to you...which is the same amount of work as taking that code out and making a working site with just the menus
Copy linkTweet thisAlerts:
@XinDec 23.2003 — actually i just need to re-create the same error, so what i need is:

- the menu page

- the js needed to show the menu on the page

i can't run asp stuffs, the view source in ie can save you a copy of the asp output and that's what i need for debugging.

thx,
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — "did you ever know that you're my hero?"

[URL=http://www.livethislife.net/ltl/downloads/Menu.zip]Menu zipfile[/URL]
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — so I'm running the html file I gave you the link for...and with the mm_menu.js file in the same folder....no error happens and the menu's work.

?

the menu's work normally anyway but they raise an error when you put the mouse over one of the images.

too bad the bosses won't go with the simple fix...turn off script debugging and hide the bottom bar in IE....
Copy linkTweet thisAlerts:
@XinDec 23.2003 — i tried it on ie and netscape7, the menu page didn't get me any error message. how is it running on your end?
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — like I said, as an html page = no errors...as an ASP.Net page (essentially an HTML page from the menu's point of view) I get an error that doesn't stop any work...but the bosses refuse to let it sit there.

oh well

thx for the help anyway
Copy linkTweet thisAlerts:
@XinDec 23.2003 — there could be a typo in the html page:

<i>
</i>&lt;A onmouseover="yxShowMenu(window.mnuReports,0,20,null,'imgReports')" onmouseout=MM_startTimeout(); href="javascript:onmouseover="MM_showMenuwindow.mnuReports 0,20,null,?imgReports?);?(,&gt;&lt;/A&gt;


the "MM_showMenuwindow.mnuReports 0" should be "MM_showMenu(window.mnuReports, 0".

thx,
Copy linkTweet thisAlerts:
@PselusauthorDec 23.2003 — it is that in my html page and the aspx page and whenever I view source...dunno how yours got like that.

I'm working on selling the bosses on just ignoring it...cause like I said everything WORKS 100% like it should...there is just an error message in IE...
Copy linkTweet thisAlerts:
@XinDec 23.2003 — from the menupage.html in your zip, just do a text search on "MM_showMenuwindow".
×

Success!

Help @Pselus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...