Check documentation for the latest version of dhtmlxSuite Event DHTMLX Docs

Event

dhtmlxEvent is a helper class for setting cross-browser handlers for events of HTML elements and DHTMLX components.

Handling events of HTML elements

To set an event handler for an HTML element, use the dhtmlxEvent() function.

<div id="mydiv" style="width:200px; height:50px; border:1px solid #ccc"></div>
 
<script>
    dhtmlxEvent (document.getElementById('mydiv'), "click", function(ev){
        alert("Hello, world!");
    });
</script>
  • element - (HTMLElement) an HTML element.
  • evName - (string) the event name (without 'on' prefix).
  • handler - (function) a handler function that takes the event object as a parameter.

dhtmlxEvent() function can be called any number of times and can be used for HTML events only


Calling the helper is a good point to start using DHTMLX components on the page.

For example, to ensure that the script written by you will be called only after the page has been completely parsed and to protect yourself from potential errors you can get in the habit of using the following technique:

//alternative to calling window.onload
dhtmlxEvent (window, "load", function(ev){
    var layout = new dhtmlXLayoutObject(document.body,"2U");
    var menu = layout.attachMenu();
    var toolbar = layout.attachToolbar();
    var grid = layout.cells("a").attachGrid();
    var form = layout.cells("b").attachForm();
    ...
})

Handling events of DHTMLX components

To set an event handler for a DHTMLX component, use the attachEvent method:

Attaching event handlers to DHTMLX components

var myForm = new dhtmlXForm("containerId", formStructure);
 
myForm.attachEvent("onButtonClick", function(name){     alert("Button with name "+name+" was clicked");});

Related sample:  onButtonClick event


To detach a handler from an event of a DHTMLX component, use the detachEvent method:

Detaching event handlers from DHTMLX components

var eventId = myForm.attachEvent("onButtonClick", function(name){ 
    alert("Button with name "+name+" was clicked");
});
 
myForm.detachEvent(eventId);

See the complete description of the mentioned methods in dhtmlxEvent API

Back to top