Retrieving texts of selected items

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
davidarnoult
Advanced
Advanced
Posts: 15
Joined: Fri Dec 10, 2004 11:09 am

Retrieving texts of selected items

Post by davidarnoult »

Hello,

I am a beginner with this menu and I try to write in my asp page the value of the current selected items.

This can be very effective to show where we are with navigation side bar as texts like

Menu1 > Item1

I have found a global variable _itemRef but when i write it, its value is always -1.

<script language="JavaScript" type="text/JavaScript">
document.write (_itemRef);

</script>

However this menu is great!
Thanks for help !

David
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Post by John »

Try here, or possibly here, or maybe here.

And thank you for the kind words!
John
davidarnoult
Advanced
Advanced
Posts: 15
Joined: Fri Dec 10, 2004 11:09 am

Yes but...

Post by davidarnoult »

Thanks for your links but I knew them already...

To write the value of current selected item in a web page, do i need to create an object of the menu first with menu = gmobj("milonic"); and them write -itemRef ??? Or do i need to modify your source codes ?
Why _itemRef is always equal to -1 in my case ?

If I succeed in helping and finding a solution for me, you can be sure I am buying your menu right now!

Thanks

David

here is contents of _mi :
itemRef=-1
0 0,Home,/,,Home,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
1 0,Products,/products/,products,,#006699,#ffffff,#CCCCCC,black,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
2 0,Services,/services/,services,,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
3 0,Success Stories,/success/,success stories,,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
4 0,News and Events,/news/,news and events,,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
5 0,Partners,/partners/,partners,,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
6 0,Company,/company/,company,,#006699,#ffffff,#000000,#ffffff,,#CCCCCC,1,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,20,,,,,,,,center,,,,,,,,,,,,,,,,,,,80,,,,,,,,#000000,solid
7 1,CAD,/products/cad/,cad,,#006699,#000000,#CCCCCC,black,,#CCCCCC,3,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,,,,,,,,,center,,,,,,,,,,,,,,,,,,,,,,,,,,,#000000,solid
8 1,CAM,/products/cam/,cam,,#006699,#000000,#006699,#ffffff,,#CCCCCC,3,10,normal,,Arial,,,black,#CCCCCC,#000000,#ffffff,0,,,,,1,,,,,,,,,center,,,,,,,,,,,,,,,,,,,,,,,,,,,#000000,solid
bparrish
Beginner
Beginner
Posts: 4
Joined: Fri Dec 03, 2004 6:01 pm

Post by bparrish »

I also have this very same question. How can a page retrieve the information about the menu items/menus which were selected to get to that page? Obviously, that information is available somewhere, because the menu system knows enough to highlight that "path" in the menu tree, should that option be turned on.

"_itemRef" only appears to refer to whatever item is currently, at that split second, being highlighted or moused-over on the current page. What I (and I presume the author of this thread) want is to find out which item was selected (and clicked) which wound us up on the page we're on.

Make sense? Anyone know how to do this?
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 David,

The likely reason that you're seeing _itemRef = -1 is that you are checking it after a new page loads.

As bparrish surmised, _itemRef is a global variable whose value constantly changes to reflect the most recent menu item pointed to. If you click on a menu item, and that item's url takes you to a different page, then that page loads the menu code anew. As a result, _itemRef will be -1 (its starting value) because no menu items have been pointed to yet on the new page.

So, what you're really looking for is the _itemRef of the last item pointed to on the previous page (that would work only if the new page loads the same menu_data.js as the previous page). So, how do you get the _itemRef from the previous page to the new page? (1) You could pass the _itemRef from one page to the next as a parameter in the url. The new page would then use a small javascript to extract the passed parameter. (2) You could use a hidden frame to store the value; it would be available from any new page in the visible frame. (3) You could store the _itemRef in a cookie, but the usual limitations of cookies would apply (e.g., it wouldn't work if the user had cookies disabled). Whatever method you use, the value you pass to the new page could then be used as an index into the menu system's _mi[] array, to extract the value of the menu item's text property.

Another approach, sort of suggested by bparrish's observation about the menu's pagematch capability, would be to loop through the menu items until you find the item whose url parameter corresponds to the current page's url. That way, you figure out the item that was (probably) responsible for getting you to the current page. That should be do-able with javascript, but you'd want to make sure to use unambiguaous urls, so that each url is not likely to be confused with multiple pages.

If you want to try any of these solutions, but aren't sure how to go about it, give a holler and I'll see if I can whip something up.

Cheers,

Kevin
bparrish
Beginner
Beginner
Posts: 4
Joined: Fri Dec 03, 2004 6:01 pm

Post by bparrish »

For those who might be curious, I accomplished this by adding various things to the end of the URL, showing where in the menu tree each link was.

So, for instance, for the top level, I add "level1=thisitem". For the next level down, I add "leve1=topitem&level2=thisitem". For the third layer down, "level1=topitem&level2=level2item&level3=thisitem".

Then I just pick up whatever "levelx" parameters get passed to the next page, and figure it out thuswise.

(Passing the "_itemRef" thing might have been a cleaner, simpler way of doing this, but I wasn't smart enough to figure that out beforehand.)
davidarnoult
Advanced
Advanced
Posts: 15
Joined: Fri Dec 10, 2004 11:09 am

Thanks for your tips

Post by davidarnoult »

Hello guys and first Happy New Year !!!! :D

To answer to Kevin and bparrish, I suggest to use, to my opinion, what is the cleaner way: with -itemRef stored in a javascript variable along the pages, method #1 described by Kevin.

However, I am not a javascript expert, and I would be very happy if somenone could give me some help to start this function...

I have to deliver my new web site to my customers end of january, I would be very happy to show them with this great menu with this functionality. If I succeed in doing this quickly, this will let me some time to order a licence of this great tool.

Thanks guys for your contribution, this forum is very helpful.

David, webmaster from France
d.arnoult@topsolid.com
davidarnoult
Advanced
Advanced
Posts: 15
Joined: Fri Dec 10, 2004 11:09 am

Giving a holler

Post by davidarnoult »

Hi Kevin !

I try to use method #1 as you explain previously but I cannot succeed in reading _itemRef value to pass it on url...

Any hints ?

Thanks a lot

David
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 David,

Sorry I never got back to this thread. Sort of forgot about it :oops:

I worked up a sample, but I'm having some trouble posting it to the support domain right now. I'll see about putting it somewhere else. Might have to wait until tomorrow.

Cheers,

Kevin
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 again David,

I posted a sample similar to what I think you want to do here. You can check it out on line and also download the sample from there.

If you have questions, I'll be back tomorrow.

Cheers,

Kevin
davidarnoult
Advanced
Advanced
Posts: 15
Joined: Fri Dec 10, 2004 11:09 am

Thanks Kevin

Post by davidarnoult »

Hi Kevin,

This is what I was looking for ! Wondeful!
Thanks very much for your great help, this is excellent.

I am just wondering if it would be possible to a link on each itemref using the url specified in the menu, in order to navigate also through these links... :D

Like :
Item1 > SubItem2
<A href='url1'>Item1</A>
<A href='url2'>SubItem2</A>

Any idea to easily do that from your work ?

Thanks again and anyway without the link this is very good.

David From France
Dagonae
Beginner
Beginner
Posts: 3
Joined: Sat Jun 13, 2009 9:28 am

Re: Retrieving texts of selected items

Post by Dagonae »

Hi Kevin... I tried your breadcrumb code, and it works like a charm. Thank you. I do notice however that once implemented, the active colours of the links are lost:

1) See http://www.designdrake.com/tvp/crumbs/index.html
2) menu path 1) Topic Here > 1.1 > 1.1.1
3) You will note the breadcrumb, but the menu has lost its active colour.

As a comparison, try the menu path 1) Topic Here > 1.1 > 1.1.2

This example does not have the breadcrumb code and holds its active links. Can you suggest a solution?

Many Thanks, Dagonae
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: Retrieving texts of selected items

Post by Ruth »

Hi,

Kevin isn't here anymore :( He did a lot of absolutely marvelous things but now there is no one who volunteers here with js function knowledge and in depth study of the menu programming. I was looking at your data file and Kevin's breadcrumb creation t to see if I could figure out anything that might be what would stop the page properties from working and the only thing I can figure is that the page url doesn't actually show a match anymore. I mean this is what I get

Code: Select all

1_1_1.html?9
as the url we reach when clicking, but the url parameter is actually

Code: Select all

javascript:mm_openUrl('1_1_1.html')
So, maybe you can use something like regexmatch in the aI also, and see if that works,

Code: Select all

aI("text=1.1.1;url=javascript:mm_openUrl('1_1_1.html');clickfunction=mm_getSelectionSequence();regexmatch=1_1_1.html;");
You would have to test this since I have no idea if it will work and no way to test it. I think what that regexmatch does is to give you a 'text' match for the url, but since that parameter is using javascript:mm_openUrl it may not work.

Ruth
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Re: Retrieving texts of selected items

Post by John »

Note that the code Kevin wrote is over 4 years old, and was not written for the current version of the menu. My guess is, because of the extensive changes to the menu code in the last 4+ years, Kevin's code is no longer relevant.
John
Post Reply