View Full Version : Modification for AnyLink Drop Down Menu

Jim Weinberg
01-29-2006, 01:36 PM
I'm using your AnyLink Drop Down Menu (http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm).

I need to display a pop-up menu when one of the drop-down links is clicked. I can do this easily enough by removing the "onClick" event from the main link description and adding it to the drop-down link's array description.

The problem is that when the link is clicked, the "onClick" script is executed and then the "href" link is invoked. If I remove the "href" from the array description, it doesn't think its a link, and if I use href="" it displays a blank window on top of the pop-up window.

Is there a way to modify the AnyLink script to not invoke the href link if its null (href="") or some other way to keep the script from executing the href?


01-29-2006, 04:30 PM
There are several ways to prevent an href from becoming activated when using an onclick event for its anchor element. The most straightforward is:

<a href="whatever.htm" onclick="dosomething();return false;">Link Text</a>

where 'dosomething();' is your onclick function call or other onclick script code.

Jim Weinberg
01-30-2006, 01:30 PM
Hi John.

I tried that, it doesn't work. Here's the array item descriptioin:

GbMenu[0]='<a href="" target="_blank" onclick="showgb()";return false;>

and here's the script I'm using to display the pop-up:
function showgb() {
var h=475
var w=550
var URL = "Gb.html";
var windowprops = "height="+h+",width="+w+",location=no,top="+(screen.height-h)/2+",left="+(screen.width-w)/2+ "scrollbars=no,menubars=no,toolbars=no,resizable=no";
popup = window.open(URL,"MenuPopup",windowprops); }
// -->


01-30-2006, 01:56 PM
This is just wrong:

GbMenu[0]='<a href="" target="_blank" onclick="showgb()";return false;>

It is so wrong, it is hard to imagine your intention for certain but, this is likely:

GbMenu[0]='<a href="#" onclick="showgb();return false;">'

This is assuming that the showgb() function has no errors. If it has errors, the href will be loaded in the normal fashion.

Jim Weinberg
01-30-2006, 06:50 PM
That worked. Thanks. I realize it was a dumb mistake, but we can't all be pros. I think I'll see if I can't find a script that displays tact. If I do, I'll send it on.:(

Again, thank you for your assistance.