View Full Version : switchmenu IE problem (remembers only the first link clicked)

02-16-2007, 10:44 AM
1) Script Title: switchmenu

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm

3) Describe problem:
I've implemented the script switchmenu, and it works just fine in FF, but not in IE. In IE it remembers the first link you click on, and only that one. I really need some help with this.

I'm using the switchmenu at www.itko.dk/home

please help

02-16-2007, 11:40 AM
Actually you've implemented the original nature of Switch Menu in two of your menu items : Karriere and Fagbeskrivelse and both of those items are working correctly without any problem in both IE and Firefox.

Have a look at the following code which is the correct format for the Switch Menu implementation according to the original script

<div style="padding-left: 0px; padding-top: 3px">
-&nbsp;&nbsp;<a class=menu onclick="javascript: switchmenu('sub4');" href="http://www.itko.dk/home/fagbeskrivelse/index.php">fagbeskrivelse</a><div>
<span class=submenu id=sub4 style="margin-left: 25px">
- <a class=menu_sub href="http://www.itko.dk/home/fagbeskrivelse/fageneenkeltvis.php">fagene enkeltvis</a>

Now the below mentioned code is from your page

<div style="padding-left:0px;padding-top: 3px;">
-&nbsp;&nbsp;<a class="menu" href="http://www.itko.dk/home/index.php" onclick="javascript: SwitchMenu('sub1');">Forside</a>
<span class="submenu" style="margin-left: 25px;" id="sub1"></span>

If you look at your code furnished just above, look at the line that I colored blue there is nothing to be displayed there so there is no switch menu there and I simply don't understand if you don't have a sub menu there why you used a SPAN element there.

Please let me know If I am stating some incorrect thing.


02-16-2007, 12:00 PM
thanks for taking the time to help.

You say that the two elements are working fine in IE?! not on the computers I've testet the script on. Thats odd... hmm

I don't think the problem is that some of the <span> tags are empty, in fact I've testet the script without these empty, and then the script doesn't work in either FF or IE...

the problem is that IE only remembers the link clicked. If I print out the cookievalue with an alert, the value is always the same (the first link clicked).

why, oh God why? :)

02-16-2007, 12:07 PM
I've tried it with IE 7 and it is showing the submenu. I don't know which version of IE you've used.

I've attached a screenshot of the same with this posting.

02-16-2007, 12:17 PM
what if you click on another link such as "Karriere", does the menu then work (show "statements") ?

I've teste it on IE 6 og 7.....

02-16-2007, 12:31 PM
ok... here is something strange: I've opened to IE windows, and it works in one of them. But this is the first one in about 25 IE windows...

Have you tried to open a new IE window and see if it still works? It seems like it isn't very stable.... and as it is now, its a now go :)

02-16-2007, 01:32 PM
in case it's not clear, I still need help... :)

02-22-2007, 12:50 PM
the problem is that IE doesn't rewrite the cookie... It only saves the cookie ones. Help please. I'm lost here...

02-22-2007, 01:33 PM
Fatal error: Class 'Afour' not found in /web/SITE/ITKO/www/home/index.php on line 17

02-22-2007, 01:57 PM
thanks a lot... it works now. :-)

02-22-2007, 01:58 PM
the " Fatal error: Class 'Afour' not found in /web/SITE/ITKO/www/home/index.php on line 17" that is. The cookie problem still exists...

02-22-2007, 06:09 PM
In a normal installation of this script, your top level items like:


shouldn't be linked. Or, you could set their links to return false, ex:

<a class="menu" href="http://www.itko.dk/home/fagbeskrivelse/index.php" onclick="SwitchMenu('sub4');return false;">Fagbeskrivelse</a>

Changing the display and the page at the same time is not how this script is normally used. IE is probably just having trouble keeping up. If you really need the page to change, it might help to do it all via javascript, like so, ex:

<a class="menu" href="http://www.itko.dk/home/fagbeskrivelse/index.php" onclick="SwitchMenu('sub4');window.location.href=this.href;return false;">Fagbeskrivelse</a>

That way, at least the page would have the chance of registering the display change and to set the cookie properly before changing to the next page. See how that goes. A timeout may need to be used if this doesn't create enough lag time for the browser. There could be other problems.

Note: An onclick event is already javascript. It doesn't require the javascript: prefix and, in fact this may be part of the trouble.

02-22-2007, 08:55 PM
thank you. Actually I've managed to solve the problem. I gave IE a domain in the cookie, and that helped. Like this:

document.cookie = name+"="+value+expires+";path=/;domain=yourdomain.dk";

FF didn't care about this...

I've deleted the javascript on the events - thanks.