MyBlogHelp– A Blog for Digital Marketing, Affiliate Marketing, Organic Lead Generation.
  • Home
  • About
  • Contact
  • Privacy
  • Sitemap
  • BLOG
  • AFFILIATE MARKETING
    • LeadsArk
  • MORE
    • MAKE MONEY
      • ONLINE BUSINESS
      • ADSENSE
      • AFFILIATE MARKETING
    • BLOGGING
      • SEO
      • BlogSpot
      • WORPRESS
      • GOOGLE
      • COMPUTER TIPS
    • WEB DESIGN
      • HTML
      • CSS
      • BOOTSTRAP
      • JAVASCRIPT
      • JQUERY
    • WEB DESIGN
      • HTML
      • CSS
      • BOOTSTRAP
      • JAVASCRIPT
      • JQUERY
    • WEB DEVELOPMENT
      • PHP
      • WORDPRESS
  • DOWNLOADS
    • Blogger Template
    • Wordpress Theme
    • PDF

Sunday, December 1, 2019

How to use JavaScript events?

 MyBlogHelp     December 01, 2019     javascript     1 comment   

JavaScript Events

 

  JavaScript - Events

  1. Introduction to JavaScript events
  2. Execute script on user action
  3. JavaScript event categories
  4. Common JavaScript events

Introduction to JavaScript Events              

With the help of JavaScript events, you can design your webpage in such a way that your webpage can respond to the user's activity and makes the necessary changes accordingly. By using events, your web page becomes even more dynamic and interactive.

Execute Script on User Action

Most events are generated by the user. So far, all the web pages you have created are fully loaded once. It means, there is no part in the webpage that remains to be loaded. But it may be that you want to load some information according to the user. As the user clicks on a link or selects an item from the menu, the page changes accordingly. You can do this with the help of a JavaScript event. 

You can use every event as an HTML attribute and handle all the events related to that tag. For example, you can use the onClick() event related to the button. As soon as a user clicks on the button, he can take action.

For example, if you add an alert box to the webpage, it shows up as soon as the webpage loads. But if you want that alert box to show when the user clicks on a button or link, then for this you will use events. Look at the example given below.

Example1: Without event
<!DOCTYPE html>
<html>
<head>
<title> Without Events Example </title>
<script type = "text/javascript">
// Alert message loading with webpage
alert("Hello, this is a warning box without events.");
</script>
</head>
<body>
<p> If you want to display this alert box according to a situation then you should use events. </p></body>
</html>


In the above example, when the webpage loads, the alert box will also be loaded with it, you can not call it a dynamic webpage. The above script generates the below output.

javascript-events-example-output
Example2: With onClick event

<!DOCTYPE html>
<html>
<head>
<title> With onClick Events Example </title>
<script type="text/javascript">
// Defining function
function message()
{
   alert ("This alert box will display when someone clicks on link.");
}
</script> 
</head>
<body>
// Calling
<a href="#" onclick="message();"> Click Here </a> </body>
</html>


The above example is given below with the onclick event.

javascript-onclick-event-example-output
The event has been used to show an alert box in this example. In this webpage, the alert box will be loaded only when the user clicks on the link. It is very easy to use events. But before using the events, you need to know about some common JavaScript events.

JavaScript Event Categories

JavaScript events have been divided into different categories. Such as related to mouse comes in mouse event category and related to form comes in the form event category. There are mostly five categories of JavaScript events.

Mouse Events
onclick, onmouseover, onmouseout, ondbclick, onmousedown,

Form Events
onblur, onchange, onfocus, onselect, onsubmit, onreset

Keyboard Events
onkeypress, onkeydown, onkeyup

Frame Events
onload, onunload, onresize, onscroll, onunload, onerror

Media Events
onplay, onpause, onerror, onprogress, onplaying

Common JavaScript Events

Below are some of the common events of JavaScript. These are the events that are used regularly.

onclick = ""
This is a mouse event. You can use it with clickable components (link, button). The defined JavaScript function calls, as the click on the Component.

onfocus = ""
This is a form event. As soon as the form gets focus, the script executes.

onblur- ""
This is also a form event, which executes the script as soon as the focus away from the form.

onchange = ""
As soon as there is a change in the component, it executes the event script. As if any other item from the list is selected.

onSelect = ""
When the user selects the text, then this event calls the define function.

onmouseover = ""
As soon as the mouse moves to the component, the script executes.

onmouseout = ""
As soon as the mouse is removed from the component, it executes the event script.

onload = ""
As soon as the page loading is completed, the script executes.

onunload = ""
As soon as a new window is opened in the browser executes the event script.

onsubmit = ""                                                                                          
As soon as the form is submitted, this event calls the defined function.


            <<-- PREVIOUS                                                          NEXT -->>









  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

1 comment:

  1. MaxFizz TechnologiesJanuary 25, 2020 at 11:28 AM

    This is really nice post, I love this content also visit website designer in jaipur. Thanks for sharing.

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Thank you for reading this post. Please do not enter any spam link in the comment box.

Followers

Blog Archive

  • ►  2020 (4)
    • ►  October (1)
    • ►  September (1)
    • ►  August (2)
  • ▼  2019 (52)
    • ▼  December (1)
      • How to use JavaScript events?
    • ►  November (2)
    • ►  October (1)
    • ►  August (1)
    • ►  July (1)
    • ►  May (11)
    • ►  April (10)
    • ►  March (6)
    • ►  February (3)
    • ►  January (16)
  • ►  2018 (54)
    • ►  December (27)
    • ►  November (5)
    • ►  May (5)
    • ►  April (4)
    • ►  February (3)
    • ►  January (10)
  • ►  2017 (17)
    • ►  December (9)
    • ►  November (8)

Popular Posts

  • How to use the main tag in html5?
  • How to use keygen tag in html5?
  • How to use html5 mark tag to highlight text?
  • How to start Online Business without money from home?
  • What is a search engine?

Contact Us

Name

Email *

Message *

About MyBlogHelp

Most of the posts, we share on this blog related to Affiliate Marketing, Organic Lead Generation, Digital Marketing, Social Media Marketing, Make Money Online, SEO, and web design.

Featured Post

LeadArk - Affiliate Marketing | Qualified Organic Lead Generation | LeadsArk Review

Copyright © MyBlogHelp– A Blog for Digital Marketing, Affiliate Marketing, Organic Lead Generation.
Design by Md. Abdussamad | MyBlogHelp.com