Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I'm trying to create a simple ajax based popup-menu or context-menu (similar to the easymenu by obout)

The user (of the control) creates the menu by adding menu items (on the server side), and specifies triggers which will make the menu pop (through javascript), but unlike the pop-up control it can have Multiple triggers.

My question is - what will be a good way to let the menu know it should pop?

I keep the IDs of the triggers in an array.

I tried adding an 'onclick ="menu.pop(x,y)" ' on every trigger, but that's a bad idea because the "onclick" may already have some code in it (like "return false;" in some cases).

I saw that obout's menu doesn't add an "onclick" event, but couldn't figure what exactly they did...

any suggestions?

Thanks in advanced,

Oren
Posted

1 solution

They may have added an onclick event, but they may not have done it inline. You can also add onclick handlers dynamically using javascript by navigating the DOM and adding the event handler to the event. For example:
JavaScript
function MyHandler(){
    alert("Hello");
}
var button = document.findElementById("someElement");
button.onclick = MyHandler;

If they do it that way, you will not see the handler when you view the HTML source.

Also, you can wrap the existing event handler with your new event handler and create one that calls both. You can do this without even knowing what event handlers are already attached to onclick. This page shows how (scroll all the way to the bottom of the page).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900