Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by P. Recktenwald on Dec 17, 2007 03:06
open dhtmlx forum
Accessing event object in event handler

Hi,

How can I access the event object in the OnClick event handler function in dhtmlxMenu?

Thank you in advance.
Answer posted by Support on Dec 17, 2007 06:03
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 ?
Answer posted by P. Recktenwald on Dec 17, 2007 09:11
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?
Answer posted by Support on Dec 17, 2007 10:03
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 )
Attachments (1)