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:28
mm_changeItemProperty
Poster: ecg921 __at__ gmail.com
Dated: Friday October 14 2005 - 17:43:30 BST
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[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
if (i == _mi.length) return;
_mi[i][codeRef] = newValue;
if (updateDisplay) BDMenu(_mi[i][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[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][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
Poster: Shap5202
Dated: Saturday October 15 2005 - 1:19:05 BST
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?
mm_changeItemProperty()
Poster: ecg921 __at__ gmail.com
Dated: Saturday October 15 2005 - 1:49:49 BST
The error occurs on ' if (_mi[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName)' is all I know. I don't know which _mi[i] 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
Poster: gmester
Dated: Thursday October 20 2005 - 0:50:41 BST
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.
Poster: kevin3442
Dated: Friday November 4 2005 - 8:17:35 GMT
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:
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 __at__ 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[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][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
Poster: gerarcyr
Dated: Friday November 4 2005 - 9:23:20 GMT
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:
var mm_separator = " > ";
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));
}
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));
}
Poster: kevin3442
Dated: Tuesday November 8 2005 - 21:18:06 GMT
gerarcyr wrote:
... but only before the first click on the menu.
Could you help me pls ?
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:
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));
}
{
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