mm_changeItemProperty

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
ecg921@gmail.com
Advanced
Advanced
Posts: 13
Joined: Thu Oct 13, 2005 7:34 pm

mm_changeItemProperty

Post by ecg921@gmail.com »

I have already sent in a support request for this two days ago but I'm not getting an answer in a timely manner, so, I am posting this on the forum.

I have a menu with 6 menu items. I want the text and bgcolor for the individual menu items to toggle back and forth when the menu item is clicked.

I am trying to use the function mm_changeItemProperty() but I keep getting the following error in IE6:

"Microsoft JScript runtime error: '_mi[...].1' is null or not an object"

Here is my mm_changeItemProperty() function:

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

Here is my function call:

mm_changeItemProperty('mapoptions', 'View<br>Cameras', 1, 'Hide<br>Cameras', 1);

As you can see, I am trying to change the menu item text 'View<br>Cameras' to 'Hide<br>Cameras'. From what I can tell, 'i' is exceeding the conditon of the for loop - _mi.length=5 but I get the error when i=6. The error occurs on ' if (_mi[1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[0]][1] == menuName)'.

I don't know if I'm suppose to have dowloaded some bolt-on module or what.

Can anyone help with this or suggest another way to change menu item properties dynamically?

Thanks,
Eric
Shap5202
Super Advanced
Super Advanced
Posts: 62
Joined: Thu Sep 29, 2005 2:36 pm

Post by Shap5202 »

do you know which _mi[...][1] is causing the error?you've got it in 3 different places. maybe just put some null checks around the code?
ecg921@gmail.com
Advanced
Advanced
Posts: 13
Joined: Thu Oct 13, 2005 7:34 pm

mm_changeItemProperty()

Post by ecg921@gmail.com »

The error occurs on ' if (_mi[1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[0]][1] == menuName)' is all I know. I don't know which _mi it is.

The for loop somehow exceeds the condition of i<_mi.length

I would like to point out that this function is from another thread concerning dynamically changing menu item properties. The link to the code is at:

http://support.milonic.com/demos/change ... /index.htm

Thanks,

Eric
gmester
Advanced
Advanced
Posts: 10
Joined: Tue Oct 11, 2005 9:54 pm

Post by gmester »

I had the same null error when I tried to use another bit of Milonic code.

For some reason the browser/code does not grab an index. If you hard code a number in place of 'i' you will see that the code responds but god help me if I can figure out why it can;t dynamically grab the i index value.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi gmester,

The "i" thing in that other code you mentioned is a different issue; you'll find an explanation here.

Eric,

I haven't been on the forums much lately, but I just stopped in and took an interest in your issue because I wrote that mm_changeItemProperty() function, although I notice that yours has an extra line in it:

Code: Select all

menuNum=getMenuByName(menuName);
That line isn't needed.

Anyway, I just tried a test, using the code you posted, and it worked fine for me (changed the text successfully). Is it possible that you are not passing the correct string for the itemName parameter? It is case sensitive, and must match exactly the text you used in the text= property of the menu item.

You mentioned that:
ecg921@gmail.com wrote: From what I can tell, 'i' is exceeding the conditon of the for loop - _mi.length=5 but I get the error when i=6. The error occurs on ' if (_mi[1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[0]][1] == menuName)'.

I'm not sure how that could happen... it's just a for loop. Since i isn't incremented within the loop, it should not be possible for it to exceed _mi.length.

If you can post a url to a page with this problem, then I should be able to tell you what's wrong. If you can't, then can you please post your menu_data.js code, and the code you are using to call mm_changeItemProperty()... if you post code, please use the forum's Code tags to preserve the formatting.

We'll get it figured out.

Kevin
gerarcyr
Advanced
Advanced
Posts: 11
Joined: Thu Nov 03, 2005 11:44 am

Post by gerarcyr »

Shap5202 wrote:do you know which _mi[...][1] is causing the error?you've got it in 3 different places. maybe just put some null checks around the code?
I've got a similar problem (Error: '_mi[...].1' is null or not an object) using the function below but only before the first click on the menu.

Could you help me pls ?

Code: Select all

var mm_separator = "&nbsp>&nbsp";
var mm_selectionSequence = "";
function mm_openUrl(url)
{
  url+="?"+_itemRef;
  window.location.href = url;
}

function mm_getSelectionSequence()
{
  var selectedItem = location.search.slice(1);
  var i = selectedItem;
  do {
    if (mm_selectionSequence == "")
      mm_selectionSequence = _mi[i][1];
    else
      mm_selectionSequence = _mi[i][1] + mm_separator + mm_selectionSequence;
    i = getParentItemByItem(i);
  } while (!isNaN(i));
}
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

gerarcyr wrote:... but only before the first click on the menu.

Could you help me pls ?
Sorry 'bout that... my fault for sloppy coding. In my defense, I had sort of slapped that example together for a specific user a long time ago; never really though that others would end up using it. Anyway, the reason you get the error message before the first click is because the mm_getSelectionSequence() function runs automatically on every page that contains your menu_data.js file (because it's called at the bottom of that file). When it runs, the function parses the "clicked" menu item that was passed to the current page from the previous page. This presents a logical error on the very first page visited, because there was no "previous" page where a menu item was clicked. Therefore, i is undefined on the first page. Again... sorry 'bout that!

Try replacing mm_getSelectionSequence() with the following version

Code: Select all

function mm_getSelectionSequence()
{
  if(location.search == "") return;
  var i = location.search.slice(1);
  do {
    if (mm_selectionSequence == "")
      mm_selectionSequence = _mi[i][1];
    else
      mm_selectionSequence = _mi[i][1] + mm_separator + mm_selectionSequence;
    i = getParentItemByItem(i);
  } while (!isNaN(i));
}
This one has a simple error check at the top: If no parameter is passed in the url, the function exits with no action taken. See if that works better for you.

Cheers,

Kevin
Post Reply