Events in JavaScript:

The interaction between JavaScript and HTML is handled by events. An event is occurred when browser or user do something on page.

An event in JavaScript means something is happens with the web page like page loading is an event, button click is also a event, selecting a radio button or checkbox is also an event.

In HTML pages JavaScript events are used to trigger JavaScript code. JavaScript has many events for HTML but we are learning about some common events that are mostly used.

JavaScript onclick event:

This JavaScript event is most common and frequently used event. This event occurs when user click on a button. You can use this event to validate your form and popup an alert for validation.

 Example:

In following example we are validating user form using JavaScript

JavaScript onsubmit Event:

This is also a very important event of JavaScript. This event occurs when user want to submit a form. So this event is use to perform form validation.

Example:

In this example we created a form and give the action “send.php” so that after submitting form the “send.php” page will open.

List of Common HTML Events:

Event Name Description
onchange Runs when HTML element changed
onsubmit Runs when form submitted
onblur Runs when element lost focus
onfocus Runs when element get focus
onclick Runs when user clicks an element
ondbclick Runs when user double click an elemnt
onkeypress Runs when key pressed and released
onkeyup Runs when key released
onkeydown Runs when key pressed
onmouseout Runs when mouse pointer moves out of element
onmouseover Runs when mouse move over an element
onmouseup Runs when mouse button is released
onmousedown Runs when mouse button is pressed
onmousemove Runs when mouse pointer moves

One response to “Events in JavaScript”

  1. Emy Watson says:

    I would like to thank you for the efforts you’ve put in writing this site. I’m hoping the same high-grade site post from you in the future too. In fact your creative writing skills has inspired me to get my own website going now. Actually blogging is spreading its wings and growing rapidly. Your write up is a good example.

Leave a Reply

Your email address will not be published. Required fields are marked *