Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:48

getMenuByName is not defined


Poster: rmorris
Dated: Monday April 4 2005 - 16:29:01 BST

Hello,

I recently upgraded my DHTML menu from 5.42 to 5.719. I wanted to use the context menu option to provide specific options on a per-link basis in our intranet.

The user is shown a menu that allows them to add, edit or delete when they right-click on a link. The menu has to be dynamically created because the URL is different for each option depending on the link they right-click on. To accomplish this I downloaded the mm_menueditapi.js bolt-on menu module. I created a context menu with placeholder menu items and then dynamically edit the menu items to specify the correct URL.

All of that seems to work fine except when I right-click on the menu, I get this "getMenuByName is not defined in mm_menueditapi.js (Line 94)" error message in the JavaScript console. I did a quick search in the mmenudom.js file and couldn't find the function in the version 5.719 but did find it in the version 5.42.

Is this function supposed to exist in the new version? If not, does the mm_menueditapi.js need to be updated so as not to call this function?

If anyone could help me or point me in the right direction, I would really appreciate it. Thank you.


Poster: Ruth
Dated: Monday April 4 2005 - 20:52:33 BST

Hi,
If this is a licensed menu, I believe you'll have to contact Milonic on that issue. Kevin is on the road this week, I believe, and he would be the volunteer on the forums who might know something about the programming and coding.

Ruth


Poster: Andy
Dated: Wednesday April 6 2005 - 10:35:35 BST

A url will help if you can provide one.

-- Andy


Poster: rmorris
Dated: Wednesday April 6 2005 - 16:14:26 BST

The page that I am working is actually on our Intranet but I have put up a test page that demonstrates the problem at:

http://hddbroker.com/contexttest/index.html

If you go to this URL you will see that under FireFox is gives the error that getMenuByName is not defined on line 94 of the file http://hddbroker.com/contexttest/menu/mm_menueditapi.js. Internet Explorer gives a similar error.

milonic_src.js:
Version 5.719 - Built: Wednesday March 23 2005 - 17:55
Type: Professional

mm_menueditapi.js:
version 1.11 - January 21 2005

If there is any other information you require, please let me know. Thanks.


Poster: Ruth
Dated: Wednesday April 6 2005 - 17:55:12 BST

I've got win98se, IE5.5, Firefox 1.0.2, Netscape7, Opera 7.54. The IE5.5 is the only one that throws an error when I right click, but the others just give me the browser option window: open link in a new window, open link in a new tab and so on.

What OS and the browser versions give the error?

Ruth


Poster: rmorris
Dated: Wednesday April 6 2005 - 18:50:35 BST

I have tested it under the following combinations:

Windows XP Home Edition SP2
- Internet Explorer 6.0.2900.2180
- FireFox 1.0.2
- Netscape 7.2
- Netscape 8.0 Beta

Windows 2000 SP4
- Internet Explorer 6.0.2800.1106

Windows 98 Second Edition
- Internet Explorer 6.0.2800.1106IS

The way I test for the error on FireFox/Netscape browsers is to open the JavaScript console and clear any messages that are already in there. Then I go to http://hddbroker.com/contexttest/index.html and right click on one of the links. If you go back to the JavaScript console, you should see the error message that is generated from the right-click of the link.

FireFox/Netscape Error Message
Error: getMenuByName is not defined
Source File: http://hddbroker.com/contexttest/menu/mm_menueditapi.js
Line: 94

Internet Explorer Error Message
Line: 95
Char: 2
Error: Object expected
Code: 0
URL: http://hddbroker.com/contexttest/index.html

Obviously the FireFox/Netscape browsers give a better explanation of the error. I have checked the mm_menueditapi.js file on line 94 and it is trying to execute _mn=getMenuByName(_mN); in the function mm_editItem(_mN, _iN, _aI).

So the handler function I created for dealing with the right-click is working as it is trying to edit the default menu but gets hung up trying to call the getMenuByName function.

Like I said before, I tried looking inside the mmenudom.js file for the getMenuByName function and there is only one match and it is actually calling getMenuByName, not defining it. In the old version that I had when I searched the file, there was one defined function called getMenuByName and 6 calls to that function.

Obviously there have been changes to the file but I don't know if those changes have anything to do with the problem that I am having right now.

Thanks for the help.


Poster: Ruth
Dated: Wednesday April 6 2005 - 19:56:40 BST

OK, I do get the error. Andy will have to look at this.

Ruth


Poster: John
Dated: Wednesday April 6 2005 - 20:11:04 BST

Where is your call for the contextmenu.js code?
Code:
<script type="text/javascript" src="contextmenu.js"></script>

See http://www.milonic.com/menusample27.php.


Poster: rmorris
Dated: Wednesday April 6 2005 - 21:02:36 BST

All the contextmenu.js does is assign a handler for when the user right-clicks anywhere in the document. This method doesn't allow for dynamic menus to be used or even allow for multiple right-click menus.

What I am trying to do is when the user right-clicks on a link, a menu will be displayed depending on the link that is right-clicked. Like if you right-click on a file in Windows, the context menu that is displayed as items in it that are specific to the file you right-clicked on. I'm trying to accomplish something similar.

Either way, there is nothing in the contextmenu.js that should affect the way I have put together the context menu. It doesn't include any external files and it doesn't define any functions needed to perform the actual right-click operation. The only relevant code in the contextmenu.js is:

Code:
_gm=getMenuByName(contextMenu)
if(_gm!=null)popup(contextMenu,1)
return false


A custom right-click menu is not only cool but very useful. If I could get this to work, Milonic could add it to their examples because I think a right-click menu that is custom based on a link would be more useful to people then a right-click menu that is the same no matter where you click on the page.

If anyone else has some other suggestions, I would be glad to entertain them.

Thank you.


Poster: kevin3442
Dated: Thursday April 7 2005 - 5:27:56 BST

rmorris,

Unfortunately, even the seemingly more informative js error messages aren't always what they seem! getMenuByName() does exist.

rmorris wrote:
Like I said before, I tried looking inside the mmenudom.js file for the getMenuByName function and there is only one match and it is actually calling getMenuByName, not defining it.

Actually, the code you found is defining the getMenubyName() function, by assigning an equivalent, previously-defined function to it. This is a means of protecting the code. The reason you're getting an error is that the call to mm_editItem() is passing the name of a menu that doesn't exist (IE's expected object), which is in turn being passed to getMenuByName(). So, there's no menu to get.

I hope you don't mind if I disagree with some of your conclusions about contextmenu.js.

rmorris wrote:
All the contextmenu.js does is assign a handler for when the user right-clicks anywhere in the document.

I have to disagree. For a small script, it does much more, including providing a contextObject that you could use to more easily do some if not all of the things you want to do.

rmorris wrote:
This method doesn't allow for dynamic menus to be used or even allow for multiple right-click menus.

Again, I have to disagree on both counts. contextmenu.js provides an object (called contextObject) that can be used in a variety of ways, such as determining which context menu to open, and modifying the contents and behavior of the context menu that opens, based on properties of the object that was right-clicked (which sounds like what you want to do). And since the name of the context menu to be opened is held in a global variable declared in contextmenu.js, you could easily have multiple right-click menus, where different menus open under different conditions.

You can find a small example of dynamic context menus using contextmenu.js here. It was made to help someone else with a different sort of dynamic context menu need, so it doesn't do exactly what you have in mind. But it demonstrates some of the same principles that could be applied to your goal, including having multiple right-click menus, and dynamically modifying the contents and/or of the context menu based on which item is right clicked. Anyway... contextmenu.js might be worth another look.

Cheers from the road,

Kevin


Poster: rmorris
Dated: Thursday April 7 2005 - 17:04:49 BST

I found out what the problem was....yeah! :)

It is actually kinda stupid but the problem was that in the file that defined the menu, I didn't have the call to drawMenus() at the end of the file. Once I put that in, the menus worked fine.

I also want to thank Kevin for your help regarding the dynamic context menu example. Even though I didn't need to use it in the end, it actually helped me find my problem.

Thanks again to all that helped.


Poster: kevin3442
Dated: Saturday April 9 2005 - 0:05:54 BST

Hi rmorris,

rmorris wrote:
I found out what the problem was....yeah! :) ... I didn't have the call to drawMenus() at the end of the file.


That's what I meant about the menu not existing.
kevin3442 wrote:
The reason you're getting an error is that the call to mm_editItem() is passing the name of a menu that doesn't exist (IE's expected object), which is in turn being passed to getMenuByName(). So, there's no menu to get.

The menu didn't exist because it hadn't been drawn. Sorry I wasn't more explicit about the drawMenus() function; probably would've been more help if I had mentioned that. :oops: But you figured it out, so good job.

rmorris wrote:
I also want to thank Kevin for your help regarding the dynamic context menu example. Even though I didn't need to use it in the end, it actually helped me find my problem.

Glad it helped.

Cheers,

Kevin