You are here: Reference > JavaScript > client-side > event handling

Event handling in JavaScript

If you need information about the event registration techniques, please see the page for the event object.

Event objects

Object Support Description
bookmarks
Represents a collection of ADO bookmarks associated with the rows affected by the current event.
boundElements
Represents a collection of elements bound to the data set on which the current event occurred.
dataTransfer
3.5
Represents a drag-and-drop operation.
event
Represents an object that contains information about an event that has occurred.

Event properties

Key related properties:
Property Support Description
altKey
(event)
Sets or retrieves a Boolean value that indicates whether the left or right ALT key was down at the time when the event occurred.
altLeft
(event)
Sets or retrieves a Boolean value that indicates whether the left ALT key was down at the time when the event occurred.
charCode
(event)
9
Retrieves the Unicode character code of the key that generated the onkeypress event.
ctrlKey
(event)
Sets or retrieves whether the left or right CTRL key was down at the time when the event occurred.
ctrlLeft
(event)
Sets or retrieves whether the left CTRL key was down at the time when the event occurred.
data
(event)
839.5
Returns the characters entered in case of the textInput event or the contents of the message for the onmessage event.
isChar
(event)
Returns whether the character that belongs to the current event is a key character or not.
keyCode
(event)
Sets or retrieves the Unicode character code of the key that generated the onkeypress event and the Unicode key code of the key that generated the onkeydown and onkeyup events.
metaKey
(event)
9
Retrieves a Boolean value that indicates whether the META key was down at the time when the event occurred.
shiftKey
(event)
Sets or retrieves a Boolean value that indicates whether the left or right SHIFT key was down at the time when the event occurred.
shiftLeft
(event)
Sets or retrieves a Boolean value that indicates whether the left SHIFT key was down at the time when the event occurred.
which
(event)
9
Returns the Unicode character or key code of the key or the identifier of the mouse button that was pressed when the current event fired.
Mouse related properties:
Property Support Description
button
(event)
Sets or retrieves the mouse button(s) that were pressed at the time when the current event was fired.
clientX
(event)
Sets or returns the x-coordinate of the mouse pointer relative to the top-left corner of the browser window's client area.
clientY
(event)
Sets or returns the y-coordinate of the mouse pointer relative to the top-left corner of the browser window's client area.
detail
(event)
9
Returns an integer value that specifies additional information about the event.
layerX
(event)
9
Retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the closest positioned ancestor element of the element that fires the event.
layerY
(event)
9
Retrieves the y-coordinate of the mouse pointer relative to the top-left corner of the closest positioned ancestor element of the element that fires the event.
offsetX
(event)
Sets or retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the offsetParent element of the element that fires the event.
offsetY
(event)
Sets or retrieves the y-coordinate of the mouse pointer relative to the top-left corner of the offsetParent element of the element that fires the event.
pageX
(event)
9
Retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the document.
pageY
(event)
9
Retrieves the y-coordinate of the mouse pointer relative to the top-left corner of the document.
screenX
(event)
Sets or retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the screen.
screenY
(event)
Sets or retrieves the y-coordinate of the mouse pointer relative to the top-left corner of the screen.
wheelDelta
(event)
Returns an integer value indicating the distance that the mouse wheel rolled.
x
(event)
Sets or retrieves the x-coordinate of the mouse pointer relative to the top-left corner of the closest relatively positioned ancestor element of the element that fires the event.
y
(event)
Sets or retrieves the y-coordinate of the mouse pointer relative to the top-left corner of the closest relatively positioned ancestor element of the element that fires the event.
Element related properties:
Property Support Description
currentTarget
(event)
9
Returns a reference to the element whose event listener is being processed.
explicitOriginalTarget
(event)
Returns a reference to the exact object on which the event originally occurred.
fromElement
(event)
Returns a reference to the object that lost the active state or that the mouse pointer left.
originalTarget
(event)
Returns a reference to the object on which the event originally occurred.
relatedNode
(event)
9
Returns a reference to the node on which the mutation event occurred.
relatedTarget
(event)
9
Returns a reference to the related element in case of onmouseover, onmouseout, dragenter and dragexit events.
srcElement
(event)
Retrieves a reference to the object on which the event occurred.
target
(event)
9
Returns a reference to the object on which the event originally occurred.
toElement
(event)
Returns a reference to the object that the mouse pointer entered.
view
(event)
9
Returns a reference to the AbstractView object where the event occurred.
Attribute related properties:
Property Support Description
attrChange
(event)
9
Returns an integer that specifies the type of the action that modified an attribute.
attrName
(event)
9
Retrieves a string that specifies the name of the modified attribute.
newValue
(event)
9
Retrieves a string that specifies the current value of the modified attribute or TextNode element.
prevValue
(event)
9
Retrieves a string that specifies the previous value of the modified attribute or TextNode element.
propertyName
(event)
Specifies or retrieves a string that contains the name of the property that is changed.
Event information properties:
Property Support Description
bubbles
(event)
9
Returns a Boolean value that indicates whether the current event can propagate up the DOM hierarchy or not.
cancelable
(event)
9
Returns a Boolean value that indicates whether the current event can be canceled or not.
cancelBubble
(event)
9
Sets or retrieves a Boolean value that indicates whether the current event should propagate up the DOM hierarchy, or not.
eventPhase
(event)
9
Returns an integer value that indicates the current processing phase of an event.
isTrusted
(event)
9
Returns a Boolean value that indicates whether the event is a trusted event or not.
repeat
(event)
Sets or retrieves a Boolean value that indicates whether the onkeydown event is being repeated (a key has been down long enough).
returnValue
(event)
Sets or retrieves a Boolean value that indicates whether the current event is canceled.
timeStamp
(event)
9
Returns the time in milliseconds when the current event occurred.
type
(event)
Retrieves a string that represents the type of the event, such as "mouseout", "click", etc.
Drag and drop properties:
Property Support Description
dataTransfer
(event)
3.5
Represents a drag-and-drop operation.
dropEffect
(dataTransfer)
3.5
Specifies or retrieves the type of the drag-and-drop operation.
effectAllowed
(dataTransfer)
3.5
Specifies or retrieves the allowed types of the current drag-and-drop operation.
files
(dataTransfer)
3.65
Returns a FileList collection that represents the dropped files during the current drag-and-drop operation.
mozItemCount
(dataTransfer)
3.5
Returns the number of dragged items during the current drag-and-drop operation.
mozUserCancelled
(dataTransfer)
3.5
Returns whether the current drag-and-drop operation has been canceled by the user.
types
(dataTransfer)
3.55
Returns a DOMStringList collection that contains the available data formats for the first item of the current drag-and-drop operation.
Data binding properties:
Property Support Description
bookmarks
(event)
Represents a collection of ADO bookmarks associated with the rows affected by the current event.
boundElements
(event)
Represents a collection of elements bound to the data set on which the current event occurred.
dataFld
(event)
Sets or returns the name of the modified data column in case of the oncellchange event.
Cross-document message properties:
Property Support Description
data
(event)
839.5
Returns the characters entered in case of the textInput event or the contents of the message for the onmessage event.
domain
(event)
9.5
10
Returns the hostname of the server that served the document that caused the onmessage event.
lastEventId
(event)
310.6
Returns the identifier of the last event in case of onmessage events.
origin
(event)
8310
Returns the scheme, hostname and port of the document that caused the onmessage event.
source
(event)
839.5
Returns a reference to the window object that contains the document that caused the onmessage event.
uri
(event)
9.5
10
Returns the location of the document that caused the onmessage event.
Additional properties:
Property Support Description
event
(script)
Sets or retrieves an event that the script element should listen for.
event
(window)
Represents an object that contains information about an event that has occurred.
horizontalOverflow
(event)
Retrieves a Boolean value that indicates the horizontal overflow state of an element when the overflowchanged event occurred.
orient
(event)
Retrieves whether the visibility of the horizontal or vertical scrollbar changed when the overflowchanged event occurred.
qualifier
(event)
Sets or retrieves the name of the default data member. Use this property with data binding events (such as ondatasetcomplete).
rangeOffset
(event)
Returns the end position of the current selection relative to the element referred to by the rangeParent.
rangeParent
(event)
Returns a reference to the element where the selection ends.
reason
(event)
Sets or retrieves an integer value that indicates whether the data transfer was successful or not. Use this property with ondatasetcomplete events.
srcFilter
(event)
Specifies or retrieves a reference to the filter object that generated the onfilterchange event.
srcUrn
(event)
Sets or retrieves the Uniform Resource Identifier (URI) of the behavior that fired the event.
verticalOverflow
(event)
Retrieves a Boolean value that indicates the vertical overflow state of an element when the overflowchanged event occurred.

Event methods

Event creation and initialization methods:
Property Support Description
createEvent
(document, XMLDocument)
9
Creates an event object with the specified type.
createEventObject
(document)
Creates an event object for message sending.
initDragEvent
(event)
9
Initializes an event object created by the createEvent method with type of 'DragEvent'.
initEvent
(event)
9
Initializes an event object created by the createEvent method.
initKeyEvent
(event)
Initializes an event object created by the createEvent method with type of 'KeyboardEvent'.
initMessageEvent
(event)
9310.6
Initializes an event object created by the createEvent method with type of 'MessageEvent'.
initMouseEvent
(event)
9
Initializes an event object created by the createEvent method with type of 'MouseEvent'.
initMutationEvent
(event)
9
Initializes an event object created by the createEvent method with type of 'MutationEvent'.
initOverflowEvent
(event)
Initializes an event object created by the createEvent method with type of 'OverflowEvent'.
initTextEvent
(event)
9
Initializes an event object created by the createEvent method with type of 'TextEvent'.
initUIEvent
(event)
9
Initializes an event object created by the createEvent method with type of 'UIEvent'.
Event assigning methods:
Property Support Description
addEventListener
9
Registers an event handler function (event listener) for the specified event on the current object.
attachEvent
Registers an event handler function (event listener) for the specified event on the current object.
detachEvent
Removes the specified event handler from the current element that was registered earlier with the attachEvent method.
removeEventListener
9
Removes the specified event handler from the current element that was registered earlier with the addEventListener method.
Event raising methods:
Property Support Description
bubbleEvent
(external)
Dispatches the current standard event from a Scriptlet Component to the browser window.
dispatchEvent
9
Dispatches the specified event to the current element.
fireEvent
Initializes an event object and dispatches it to the current element.
getPreventDefault
(event)
Returns whether the default action of the current event is canceled or not.
postMessage
(window)
839.5
Provides communication between two documents regardless of their location.
preventDefault
(event)
9
Cancels the current event.
raiseEvent
(external)
Dispatches the specified custom event from a Scriptlet Component to the browser window.
stopPropagation
(event)
9
Disables the propagation of the current event in the DOM hierarchy.
Event capturing methods:
Property Support Description
captureEvents
(document, window)
3
Tells the document or window object to capture the specified types of events.
disableExternalCapture
(window)
3
Disables event capturing for documents that are located in different domains.
enableExternalCapture
(window)
3
Allows event capturing for documents that are located in different domains.
releaseCapture
Releases the mouse capture from the browser window that was previously set by the setCapture method and restores the normal event processing.
releaseEvents
(document, window)
3
Stops capturing the specified events that was previously set by the captureEvents method.
setCapture
Sets the current object to capture mouse events that occur within the entire browser window.
Event simulation methods:
Property Support Description
blur
Removes the focus from the current element, and fires the onblur event.
click
Simulates a mouse click on the current element.
doScroll
(body, div, html, span, textarea)
Simulates a mouse click on the specified scrollbar component of the current element.
dragDrop
Initiates a drag-and-drop operation.
focus
Sets the focus on the current element.
reset
(form)
Restores the contents of the elements contained by the current form to its original value.
setActive
Sets the element as the active element in the current document.
submit
(form)
Submits the data placed in the current form element.
Drag and drop methods:
Property Support Description
addElement
(dataTransfer)
3.5
Specifies the feedback image for the current drag-and-drop operation.
clearData
(dataTransfer)
3.5
Removes the specified formatted data from the current drag-and-drop operation.
getData
(dataTransfer)
3.5
Retrieves the specified formatted data from the current drag-and-drop operation.
mozClearDataAt
(dataTransfer)
3.5
Removes the specified formatted data associated to the dragged item at the specified position from the current drag-and-drop operation.
mozGetDataAt
(dataTransfer)
3.5
Retrieves the specified formatted data associated to the dragged item at the specified position from the current drag-and-drop operation.
mozSetDataAt
(dataTransfer)
3.5
Specifies the data, its format and the associated position for the current drag-and-drop operation.
mozTypesAt
(dataTransfer)
3.5
Returns a DOMStringList collection that contains the available data formats for the item at the specified position in the current drag-and-drop operation.
setData
(dataTransfer)
3.5
Specifies the data and its format for the current drag-and-drop operation.
setDragImage
(dataTransfer)
3.5
Specifies the feedback image and the mouse cursor position for the current drag-and-drop operation.

Events in JavaScript

Character input and clipboard events:

Property Support Description
onbeforecopy
Occurs before the selection is copied to the clipboard and before the oncopy event.
onbeforecut
Occurs before the selection is cut from the document and provides a possibility to enable the Cut menu item.
onbeforepaste
Occurs before the contents of the clipboard are pasted into the document and provides a possibility to enable the Paste menu item.
oncopy
Occurs before the selection is copied to the clipboard.
oncut
Occurs before the selection is cut from the document and added to the clipboard.
oninput
9
Occurs when the text content of an element is changed through the user interface.
onkeydown
Occurs on an element that has the focus when a key is pressed down and occurs periodically until the key is released.
onkeypress
Occurs on an element that has the focus when a key is pressed down and occurs periodically until the key is released.
onkeyup
Occurs on an element that has the focus when the user releases a key.
onpaste
Occurs before the contents of the clipboard are pasted into the document.
textInput
9
Occurs when some characters are entered into an element.

Load, unload and state events:

Property Support Description
onabort
Occurs when the user aborts the loading of an img or input:image element.
onbeforeunload
Occurs before the browser unloads the document and provides a possibility to display a confirmation dialog, where the user can confirm whether he wants to stay or leave the current page.
onhashchange
83.610.65
Occurs when the hash subsection (begins with a '#' sign) of the current document's URL has changed.
onload
Occurs when an object has been loaded.
onoffline
83
Occurs when the browser starts to work offline.
ononline
83
Occurs when the browser starts to work online.
onreadystatechange
Occurs when the load state of the data that belongs to an element or a HTML document changes.
onreadystatechange (XMLDocument)
Occurs when the load state of the XMLDocument object changes.
onreadystatechange (XMLHttpRequest)
Occurs when the state of the request changes.
onstop
Occurs when the user aborts the loading of the document.
onunload
Occurs before the browser unloads the document.

Form events:

Property Support Description
onreset
Occurs on a form before it is reset.
onsubmit
Occurs on a form element when the user clicks on a submit button in the form.

Mouse events and scrolling:

Property Support Description
onclick
Occurs when the user clicks on an element.
oncontextmenu
10.5
Occurs when the right mouse button is clicked on an element and the context menu is shown.
ondblclick
Occurs when the user double clicks on an element.
onlosecapture
Occurs when the object loses the mouse capture.
onmouseenter
Occurs when the user moves the mouse pointer into the area of an element.
onmousedown
Occurs when the user presses a mouse button over an element.
onmouseleave
Occurs when the user moves the mouse pointer out of the element.
onmousemove
Occurs when the user moves the mouse over the element.
onmouseout
Occurs when the user moves the mouse pointer out of the element.
onmouseover
Occurs when the user moves the mouse pointer into the element.
onmouseup
Occurs when the user releases a mouse button over an element.
onmousewheel
Occurs when the mouse wheel rolls.
onscroll
Occurs when the contents of an element have been scrolled.

Move and drag events:

Property Support Description
onmove
Occurs when the position of an element's top-left corner is changed.
onmoveend
Occurs when the user stops dragging an absolute or relative positioned element in an editable region.
onmovestart
Occurs when the user starts dragging an absolute or relative positioned element in an editable region.
ondrag
3
Occurs periodically on the source element during the drag operation.
ondragend
3
Occurs on the source element when the user has finished the drag operation.
ondragenter
Occurs on an element when the user moves the mouse pointer into it during a drag operation.
ondragleave
3.5
Occurs on an element when the user moves the mouse pointer out of it during a drag operation.
ondragover
Occurs periodically on an element while the mouse pointer is over it during a drag operation.
ondragstart
3.5
Occurs on the source element when the user starts the drag operation.
ondrop
3.5
Occurs on a possible target element when the dragged data is dropped on it.

Resize events:

Property Support Description
onresize
Occurs when the size of an object has changed.
onresizeend
Occurs when the user stops resizing an element in an editable region.
onresizestart
Occurs when the user starts to resize an element in an editable region.

Activation and focus events:

Property Support Description
onactivate
Occurs when an element becomes active.
onbeforeactivate
Occurs before an element becomes active.
onbeforedeactivate
Occurs on the active element before it loses the active state.
onbeforeeditfocus
Occurs before an input:file, input:password, input:text or textarea element or an element in an editable region becomes a UI-activated.
onblur
Occurs when an element loses focus.
ondeactivate
Occurs on the active element when it loses the active state.
onfocus
Occurs when an element receives focus.
onfocusin
Occurs before an element receives focus.
onfocusout
Occurs after an element loses focus.

Selection events:

Property Support Description
oncontrolselect
Occurs before a control is selected in an editable region.
onselect
Occurs after some text has been selected in an element.
onselectionchange
Occurs when the selection in the document has changed.
onselectstart
Occurs at the start of a selection process.

Print and help events:

Property Support Description
onafterprint
Occurs when the browser has built the contents of the current document for printing or for the print preview.
onbeforeprint
Occurs when the browser starts to build the contents of the current document for printing or for the print preview.
onhelp
Occurs after the user has pressed the F1 key.

Error events:

Property Support Description
onerror
Fires when an error occurs while loading an external file.
onerror (window)
Fires when a script error occurs.
onerrorupdate
Occurs on a databound object when it cannot update the data in the data source object.

DataBound events:

Property Support Description
onafterupdate
Occurs on a databound object after it updates the data in the data source object.
onbeforeupdate
Occurs on a databound object before it updates the data in the data source object.
oncellchange
Occurs on a data source object when the data in it has changed.
ondataavailable
Occurs each time when a new chunk of data becomes available from the source.
ondatasetchanged
Occurs on a data source object when the initial or a new data set becomes available.
ondatasetcomplete
Occurs on a data source object when all its data becomes available.
onrowenter
Occurs on a data source object when the current row in it has changed.
onrowexit
Occurs on a data source object before the current row in it changes.
onrowsdelete
Occurs on a data source object before rows are deleted.
onrowsinserted
Occurs on a data source object when rows have been inserted.

Marquee events:

Property Support Description
onbounce
Occurs when the contents of a marquee element touch one side of the marquee element's bounding rectangle.
onfinish
Occurs when a marquee element has finished the scrolling animation.
onstart
Occurs when a marquee element begins the scrolling animation and when a new loop starts.

Change events:

Property Support Description
onchange
Occurs when the selection, the checked state or the contents of an element have changed. In some cases, it only occurs when the element loses the focus.
onfilterchange
Occurs after a filter has changed or finished a transition.
onpropertychange
Occurs every time when the value of an element's property is changed.

Search event:

Property Support Description
onsearch
Occurs when the user presses the ENTER key or clicks the 'Erase search text' button (x) in an input:search field.

Cross-document communication event:

Property Support Description
onmessage
83
Occurs when the postMessage method sends a message to the current window.

Additional events:

Property Support Description
CheckboxStateChange
Occurs when the state of a checkbox has changed.
DOMActivate
Occurs when an element becomes active.
DOMAttrModified
9
Fires when an attribute is added, removed or when the value of an attribute is modified by script.
DOMCharacterDataModified
9
Fires when a script changes the value of a TextNode.
DOMFocusIn
Occurs before an element receives focus.
DOMFocusOut
Occurs before an element loses the focus.
DOMMouseScroll
Occurs when the mouse wheel rolls.
DOMNodeInserted
9
Occurs on a node when it is added to an element.
DOMNodeInsertedIntoDocument
Occurs on a node when it is inserted into the document.
DOMNodeRemoved
9
Occurs on a node when it is removed from its parent.
DOMNodeRemovedFromDocument
Occurs on a node when it is removed from the document.
DOMSubtreeModified
9
Fires on a node when a modification occurs in the subtree that belongs to it.
dragdrop
3.5
Occurs on a possible target element when the dragged data is dropped on it.
dragexit
Occurs on an element when the user moves the mouse pointer out of it during a drag operation.
draggesture
Occurs on the source element when the user starts the drag operation.
overflow
Occurs when the contents or the size of an element is changed and it causes a scrollbar to appear.
overflowchanged
Occurs when the contents or the size of an element is changed and it causes a scrollbar to appear or disappear.
RadioStateChange
Occurs when the state of a radio button has changed.
underflow
Occurs when the contents or the size of an element is changed and it causes a scrollbar to disappear.
User Contributed Comments

Post Content

Post Content