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: Thursday February 8 2018 - 06:02:16

Dynamically change URL for popup


Poster: JeffW
Dated: Wednesday January 14 2004 - 22:07:54 GMT

I'm using popup to display multiple choices on a link -- actually, on a set of links within a page -- and would like to change the menu URLs based upon the current link. Does anyone know how to do this? I assume the following gets me to the menu object in question but how do I reference the individual items and the URL within each item?

_mn = getMenuByName("mymenu");
_m[_mn]...

Thanks in advance for any advice.


Poster: kevin3442
Dated: Thursday January 15 2004 - 7:57:48 GMT

Hi Jeff,

You've figured out how to get the "menu number", which you've seen is the index into the menu array (there's actually another step to getting a reference to the object itself). But as you've also seen, that's not really the main issue here. To rephrase what you stated, the main issue is figuring out how to get to the menu item, then how to get to the various properties of that item.

Note: the following is a lengthy explanation because (a) sometimes I'm just long winded and (b) there may be others out there who are interested, and I figured if I explained in detail here, I could just refer to this thread for future seekers of arcane menu stuff.

Internally, everything that you configure in the menu_data.js code ends up in one array or another. _m[] is an array of menus. _mi[][] is an array of menu items; its first dimension is from 0 to the total number of items combined from all of the various menus (minus 1 of course), and its second dimension holds the setting of each menu item property. So, its like this: _mi[item][property], where the second dimension is indexed by the "Code Ref" numbers given in the quick reference table for menu item properties.

Hope that made sense so far... if it did, you'll realize that, in theory, once you know the indexes, it's pretty straight forward to set or get any property for any menu item. In practice, however, it's the "once you know the indexes" part that's tricky. The index to the second dimension is easy... all of them appear in the quick ref table I mentioned earlier. So the hard part is finding the index into _mi[][]'s first dimension, to target the specific menu item(s) you want to change. I could not find a built-in method of doing that (I may have just missed it), so I did it myself. The following function will find the item you specify and change whatever property you want to change:

Code: Select all

function mm_changeItemProperty(menuName, itemName, codeRef, newValue, updateDisplay)
{
  menuName = menuName.toLowerCase();
  for (i=0; i<_mi.length; i++)
    if (_mi[i][1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
  if (i == _mi.length) return;
  _mi[i][codeRef] = newValue;
  if (updateDisplay) BDMenu(_mi[i][0]);
}

This function takes five parameters.

(1) - menuName is the name of the menu containing the item you want to change. This parameter is necessary to differentiate among items containing the same text but in different menus. The menuName is given in the code that creates the menu. It is not case sensitive. For example, if you create a menu with the following code:

Code: Select all

with(milonic=new menuname("Software")){
style=menuStyle;
...other properties and item definitions...
aI("text=Downloads Page;url=downloads.html;");
}

then the name of the menu (its menuName) is given in the first line as 'Software'.

(2) - itemName is the name of the item whose properties you want to change. Since the menu system does not assign an internal item name, I use the text that appears in the menu item itself, and so the itemName is given in the text= property of the aI() function that defines the menu item. It is case sensitive. So, for example, in your 'Main Menu', if you have a 'Downloads Page' item defined like so:

Code: Select all

aI("text=Downloads Page;url=downloads.html;");

then the itemName of this menu item is 'Downloads Page'. We're looking for an exact match here, so remember that it is case sensitive, and leading and trailing spaces also count. Speaking of spaces, when calling the function, substitute a normal space in itemName for any &nbsp; in the text property of the item's aI() definition. For example, if your menu item was defined with one or more non-breaking spaces, like so:

Code: Select all

aI("text=Downloads&nbsp;Page;url=downloads.html;");

then the itemName you pass in the function call would still be 'Downloads Page'.

(3) - codeRef is the index or "code reference" of the property that you want to change. Each menu item property has a unique "code reference" number; these numbers are found in the "Code Ref" column of the quick reference table that lists the menu item properties. For example, the codeRef for an item's offbgcolor property is 7, the codeRef for the item's URL property is 2.

(4) - newValue is the new value that you want to assign to the identified menu item property, for the targeted menu item. This might be a numeric or a string value, depending on what type of property you are changing (a color or URL would be a string, widths would be numeric).

(5) - updateDisplay is a boolean indicating that you do (true) or do not (false) want to force an immediate update for display pruposes. You'd typically want to use true for visual properties, like color or size, especially if the menu is already visible when you make the change. You could use false for "behavioral" properties, like openonclick or the URL, things that won't be used until the next time the item is moused over or clicked (using true for these shouldn't hurt, I think, but would cause an additional, probably unnecessary function call).

So, using the examples above, the starting URL for the "Downloads Page" menu item in the "Software" menu is "downloads.html". Suppose you wanted to change that URL to "trialDownloads.html"... you'd do so like this:

Code: Select all

mm_changeItemProperty('Software','Downloads Page',2,'trialDownloads.html',0);

In your case, you could change URLs in your popups by calling mm_changeItemProperty() from the onmouseover event in the link, before you call popup(). You might even want to wrap the calls to mm_changeItemProperty() and popup() inside of your own function, to simplify the coding for multiple links.

OK... so, like... it's late, you dig? I hope what makes sense to me at 1:50 AM makes sense to you at a more normal hour! I'm clicking the "Submit" button...

Hope that helps,

Kevin


Poster: JeffW
Dated: Thursday January 15 2004 - 12:14:32 GMT

Kevin: A 5-star reply, just what I needed, many, many thanks.


Poster: kevin3442
Dated: Thursday January 15 2004 - 16:22:28 GMT

JeffW wrote:...A 5-star reply, just what I needed, many, many thanks.


One star per parameter! You're welcome Jeff. Do me a favor and let me know if it works. I forgot to mention that I had only played with this extensively in IE6/Win2k. Haven't really done much property changing in other browser/os combos.

Kevin

mm_changeItemProperty crashes IE on a MAC


Poster: oviroa
Dated: Monday January 10 2005 - 18:21:37 GMT

mm_changeItemProperty crashes IE on a MAC. Any idea why?


Poster: Bob Martin
Dated: Wednesday March 2 2005 - 21:42:10 GMT

Excellent documentation for most of what I need to do, and it has worked like a champ so far. Now, how do you change a menu's page properties, like bgcolor, after it has been displayed?


Poster: Ruth
Dated: Wednesday March 2 2005 - 23:33:51 GMT

I think this will not work on a menu, only on items, so you'd use the item number, for whichever bgcolor you want, on or off and use that to make the change. The offbgcolor reference number is 5 and the onbgcolor is 7. You can find the reference numbers for properties in the Menu Quick Reference Guides on the Home Page Menu under DHTML Menu link. They are listed for style, menu and item properties. I think I may have the links below my name. There are also clickbgcolor and clickcolor and I Think a clickclass or image.

Ruth


Poster: Ruth
Dated: Thursday March 3 2005 - 10:14:06 GMT

Someone must have been thinking of you :!: As I was searching for something else I found this topic which seems to refer to a function to change menu properties, not just items. Not sure if that is what you need, but since it said modifying menu properties I thought you might want to check it.

Ruth