JS Events

JavaScript Events

JavaScript Events

A JavaScript function is a section of code that perform a specific task when called. Calling a function is achieved by its name.

Syntax:

function function_name() 
  {
    function code
  }

Example:

<html>
<head>
<script>
function helloFunction()
{
alert("Hello people!");
}
</script>
</head>
<body>
<input type="button" onclick="helloFunction()" value="Press button" />
</body>     
</html>

Result:


JavaScript Event Handlers

Event handling is to drive action following the event, such as onClick, onMouseOver, onKeyUp.
Drive or treating an event brings drive a JavaScript function that will take over the tasks assigned to the event.

EventDescription
onBlurAction that will be triggered when an element loses focus on.
onChangeAction that will be automatically triggered when changing an item.
onFocusAction that will be triggered by focusing on an element.
onResetAction will be initiated when the reset button of a form is pressed.
onSelectAction that will be triggered when selecting an item.
onSubmitAction will be initiated when the submit button of a form is pressed.
onClickAction that will be triggered when you press left click on the mouse.
onDblClickAction that will be triggered when double click the left mouse button.
onMouseDownAction that will be triggered when a mouse button is pressed.
onMouseMoveAction that will be triggered when the mouse cursor moves.
onMouseOutAction that will be triggered when the mouse cursor moves outside
item or area bounded.
onMouseOverAction that will be triggered when the mouse pointer moves over a
element or over the surface area.
onMouseUpAction that will be triggered when the mouse button is released.
onKeyDownAction that will be triggered when a key is pressed.
onKeyPressAction that will be triggered when you press and release a key.
onKeyUpAction that will be triggered when a key is released.
onErrorAction that will be triggered after loading an image or failure of a
document.
onLoadAction that will be automatically triggered when loading a document.
onUnLoadAction that will be automatically triggered when a document doesn’t load.