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:10

Menus on the fly


Poster: ayhan __at__ drexel.edu
Dated: Wednesday September 24 2003 - 17:31:34 BST

Hi all,

Is it at all possible to dynamically create and display menus within a page?

I downloaded the "menu_sample3" (Static HTML ) and started tweaking it.

The problem is... the "menu_data.js" paradigm doesn't really cut it for me.

That is, I need to dynamically create multiple menus, or at least be able to modify the menu items of a single "re-usable" menu.

Is that possible?

Below is an HTML snippet that shows how I had expected to work. But it doesn't. I just get an "Object required" error.

The rest of the JS files are the same as "menu_sample3".



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<SCRIPT language=JavaScript src="milonic_src.js" type=text/javascript></SCRIPT>
<script language=JavaScript>
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>

<SCRIPT language=JavaScript src="menu_data.js" type=text/javascript></SCRIPT>

<script type="text/javascript">

function show_context_menu(url) {
var url_encoded = encodeURIComponent(url);

var url_view = "http://example.com/view.cgi?url=" + url_encoded;
var url_edit = "http://example.com/edit.cgi?url=" + url_encoded;

with(milonic = new menuname("On The Fly")){
style=menuStyle;
aI("text=View;url=" + url_view + ";");
aI("text=Edit;url=" + url_edit + ";");
};
drawMenus();
popup("On The Fly",1);
}

</script>


</head>

<body>


<a href=# onmouseover="show_context_menu('http//example.com/readme.txt')" onmouseout=popdown()><font size=3 color=green>On The Fly</font></a>
<a href=# onmouseover="popup('milonic',1)" onmouseout=popdown()><font size=3 color=green>Milonic</font></a>
<br>
<br>
</body>
</html>


Poster: DMLCo
Dated: Wednesday September 24 2003 - 17:41:53 BST

The short answer is YES.

You can script the creation of menus using anything from JavaScript to Cold Fusion to ASP to PHP. The key is to get the syntax correct.

Looking quickly at your code, there is no need for the creation of an additional function--you should use the popup() function to control the display of the menu. Build the AI calls dynamically the way you are, but in raw script (that is, not as part of a function). The menus need to be built and ready before being called ...

-Daniel


Poster: ayhan __at__ drexel.edu
Dated: Wednesday September 24 2003 - 18:07:12 BST

Thanks for your prompt reply Daniel.

I guess I should have explained the motive of the exercise better.

We're working on a Web based directory browser.


The files on a server directory are displayed in an HTML table, one entry per line. It's possible to have several hundreds per page.

BTW, this stuff is completely server-side (perl) script generated anyway.

Basically, I need a context sensitive menu similar to what you've got when you explore a Folder's contents on Windows (which appears via a right-click on a file), with items such as "View", "Edit", "Delete", ...

Let's say we have 100 files in a folder, which are listed in an HTML table.

Now, I guess I do have the option of generating 100 menus on the server side, sticking them in the HTML and then calling them with popup(..).

context_menu_001
context_menu_002
...
context_menu_099

The thing is, these menus would have pretty much the same thing except their action urls.

This solution (or workaround) seems to be quite costly in network bandwidth and server-side CPU. That's why I would like to avoid it.

What I was looking for really is a way to create the menu when it is needed, that is, just before it is displayed.

And that's why I put it in a function, so that it happens on the client side, as a result of some user action that would trigger it.

Are you still with me?


Thanks again,
Ayhan


Poster: Hergio
Dated: Wednesday September 24 2003 - 22:38:59 BST

Off the top of my head, I dont think this is possible with the menu without some tweaking and hacking. Milonic is currently about to undertake adding a feature to the menu that will allow for menus created on the fly. This would mean that only when a menu is called for is it actually rendered....very quick loading. But like I said, I havent thought about it much, but I doubt its possible at the moment. Andy may know better.


Poster: ayhan __at__ drexel.edu
Dated: Thursday September 25 2003 - 13:35:18 BST

Thanks Dave,

I was afraid that would be the case. :(

I am suspecting the use of lower level functions such as _drawMenu() and menuDisplay() directly instead of popup(), which I have -unsuccessfully- tried, but don't really know how to go about it?

Would anyone have an idea just how one could go about that tweaking & hacking?

Cheers,
Ayhan


Poster: John
Dated: Thursday September 25 2003 - 15:10:58 BST

ayhan __at__ drexel.edu wrote:
Would anyone have an idea just how one could go about that tweaking & hacking?

Typically not a good idea. Andy's code is very tight, not to mention the fact he's always upgrading and making additions to it. If he were to come up with a nifty new feature you really want you'd have to start hacking all over again just to get the new and keep your old.

Besides, he is very receptive to good suggestions. I've seen him add new items in less than a day. Just ask in the appropriate area.


Poster: ayhan __at__ drexel.edu
Dated: Thursday September 25 2003 - 16:47:00 BST

You're absolutely right, John.

Besides, if I gather correctly from Dave's message + the Feature Request area, it seems that Andy has already got something up his sleeves for this one.

I may go ahead and post a "Feature Req", just to be included in the statistics of those who ask for it. ;) :lol:

Cheers,
Ayhan