Hi,
How can I access the event object in the OnClick event handler function in dhtmlxMenu?
Thank you in advance.
Actually there is no way get DOM event from code of OnClick event handler of menu.
Custom event handler receives the ID of selected menu item, which is enough in most cases, which additional parameters you need to take from event object ?
Thank you for your answer. My scenario is as follows:
I have a TreeGrid and used click buttons to perform actions like adding a new elements, deleting elements etc. As I encoutered problems, with these actions, I looked up the knowledge base for a solution and found to add event.cancelBubble=true; to the buttons onclick part like this:
<input type=“button” id=“addChild” name=“addChild” value=“Add Child” onclick=“addChild(mygrid.getSelectedId());event.cancelBubble=true;”>
Now I removed the buttons to use dhtmlxMenu instead. So I moved these actions in the onclick="…" part of the buttons to the OnClick event handler of a dhtmlxMenu menubar, which looks like this:
function onMenuBarItemClick(menuItemId,menuItemValue){
switch(menuItemId){
…
case “add_child”:
addNewItemAsChild(mygrid.getSelectedId());
event.cancelBubble=true;
break;
…
}
}
menuBar.setOnClickHandler(onMenuBarItemClick);
But setting event.cancelBubble=true is not possible here, as the event is not accessible… What can I do instead?
This not necessary in case of dhtmlxmenu, existing code already executes similar code against any event which occurs inside menu.
( not sure which version of menu do you use, just to be sure, latest js file attached )
dhtmlxmenubar.zip (10.4 KB)