Technical Training
JavaScript TutorialJavaScript Events Handling
JavaScript Events Handling
In this JavaScript tutorial, you will learn about handling events in JavaScript, what is event handling in JavaScript? events in JavaScript, events associated with mouse - onmousemove, onclick, ondblclick, onmouseout, onmouseover, events associated with keyboard - onkeydown, onkeyup, onkeypress. onerror, onfocus, onblur, onsubmit, onload and onunload.
Ads
What is Event Handling in JavaScript?
This is a very vital concept of JavaScript because without events there would be no code. Event handling is the execution of code for the user’s reaction. In other words, when a user performs some action, the associated event fires or executes. For example, if a programmer want a piece of code to execute when a user presses a button, then the code is placed in the onclick event of the button, executing the code when the user clicks that button. In addition, there are events in JavaScript that are automatically fired without the intervention of the user. The load event fires when the page loads. Thus, there are various scenarios for firing events such as:
- 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.
Events in JavaScript:
There are numerous events in JavaScript, some of which are listed below. A particular object has numerous events associated with it, depending on the action taken by the user.
For example, the object mouse has numerous events associated with it which depend on the user’s actions.
Events associated with Mouse:
onmousemove:
If the user moves a button, then the events associated with onmousemove fire.
onclick:
onclick events fire when the mouse button clicks.
ondblclick:
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:
onmouseout event fires if the mouse pointer position is out of focus from the element.
onmouseover:
onmouseover event fires if the mouse pointer position is in focus of the element position.
The above are some of the various mouse events available in JavaScript.
Events associated with Keyboard:
- onkeydown
- onkeyup
- onkeypress
onkeydown:
onkeydown event fires when key is pressed.
onkeyup:
onkeyup event fires when key is released.
onkeypress:
The event onkeypress fires if the onkeydown is followed by onkeyup.
There are many additional events available in JavaScript. A few are listed below:
onerror:
onerror event fires when an error occurs.
onfocus:
When a element gains focus, onfocus event fires or executes.
onblur:
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.
onsubmit:
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:
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.
onunload:
In contrast to onload event, the onunload event fires when the user leaves the page.
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







