- When the user performs some action based on which event fires
- When the page load event fires
- When some fields change, the associated events fire.
For example, the object mouse has numerous events associated with it which depend on the user’s actions.
Events associated with Mouse:
If the user moves a button, then the events associated with onmousemove fire.
onclick events fire when the mouse button clicks.
The event ondblclick fires when the mouse button is double clicked.
There are also some events associated with the mouse pointer position such as:
onmouseout event fires if the mouse pointer position is out of focus from the element.
onmouseover event fires if the mouse pointer position is in focus of the element position.
Events associated with Keyboard:
onkeydown event fires when key is pressed.
onkeyup event fires when key is released.
The event onkeypress fires if the onkeydown is followed by onkeyup.
onerror event fires when an error occurs.
When a element gains focus, onfocus event fires or executes.
In contrast to an onfocus event, this event fires when the element loses its focus. Both onfocus and onblur may be used for handling validation of forms.
The event onsubmit fires when the command form submit is given. This event is used for validating all fields in the form before submitting the form.
onload event automatically executes as soon as the document fully loads. This loads when the user enters the page. This is a commonly used event. This event is used to check compatibility with the browser version and type. Based on this compatibility, the appropriate version of a page will then load.
In contrast to onload event, the onunload event fires when the user leaves the page.