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.

Event Description
onBlur Action that will be triggered when an element loses focus on.
onChange Action that will be automatically triggered when changing an item.
onFocus Action that will be triggered by focusing on an element.
onReset Action will be initiated when the reset button of a form is pressed.
onSelect Action that will be triggered when selecting an item.
onSubmit Action will be initiated when the submit button of a form is pressed.
onClick Action that will be triggered when you press left click on the mouse.
onDblClick Action that will be triggered when double click the left mouse button.
onMouseDown Action that will be triggered when a mouse button is pressed.
onMouseMove Action that will be triggered when the mouse cursor moves.
onMouseOut Action that will be triggered when the mouse cursor moves outside
item or area bounded.
onMouseOver Action that will be triggered when the mouse pointer moves over a
element or over the surface area.
onMouseUp Action that will be triggered when the mouse button is released.
onKeyDown Action that will be triggered when a key is pressed.
onKeyPress Action that will be triggered when you press and release a key.
onKeyUp Action that will be triggered when a key is released.
onError Action that will be triggered after loading an image or failure of a
document.
onLoad Action that will be automatically triggered when loading a document.
onUnLoad Action that will be automatically triggered when a document doesn’t load.