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

Disable or Modify Menu items based on page being viewed

Poster: jshep __at__
Dated: Friday January 21 2005 - 1:00:00 GMT

I have a number of "common" menu items that are displayed on all pages at various directory levels. I would like to disable or modify menu items based on the page being viewed. Can anyone suggest an easyway of doing this?



Poster: Ruth
Dated: Friday January 21 2005 - 7:57:37 GMT

I'm not sure either of these topics will help, but THIS one has to do with inserting items, and farther down in the topic is information on a function to remove an item. THIS topic has information on removing items and a module for editing items. Hope this helps.


Poster: twisted6
Dated: Friday January 21 2005 - 18:12:54 GMT

I use this technique very often...

Put these two statements near the top of the menu_data.js file.
var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
var thefile = location.href.substring(dir.length,location.href.length+1);

Check the file where appropriate. This logic enables the menu item for a specific page, but you just have to change the If statement to suit your application.
if (thefile == "about.html")   {   
   aI("text=Conditional Page;url=whatever.html");

If you want to check for all files that start with a particular string, eg. prod*, try this:
if (thefile.substring(0,"prod".length) == "prod")   {
   aI("text=Conditional Page;url=whatever.html");

Poster: Ruth
Dated: Friday January 21 2005 - 22:10:54 GMT

Thanks for the help, Twisted6. We really appreciate it. :D


Poster: kevin3442
Dated: Monday January 24 2005 - 21:32:09 GMT

Hi Jim,

jshep __at__ wrote:
...I would like to disable or modify menu items based on the page being viewed...

Twisted6's ideas are very useful if you want to conditionally include or exclude a menu item in a menu. In other words, by wrapping the call to aI() inside of an "if", the menu item defined by that aI() call will appear in the menu if the condition is met, but will not appear at all in the menu if the condition is not met.

Extending Twisted6's approach, you could always include an item in a menu, but have it appear to be enabled or disabled depending on the conditional test. (You could make an item appear to be disabled by altering the oncolor, onbgcolor, etc... there's even a type=disabled item property that you might find useful). In other words, you could add an "else" to the condition:
if (condition is met) {
  aI("..."); // menu item with enabled appearance and behavior
else {
  aI("..."); // menu item with disabled appearance and behavior.

Finally, if you want to be able to modify a menu item's appearance and behavior programatically, after the page has been rendered, you can do so with a function called mm_changeItemProperty(), which is described in detail in this post.