iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning JavaScript Course: Event handler - www.itechcollege.com JavaScript Course: Event handler - www.itechcollege.com
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

courses > JavaScript > Event handler

Event handler

What are event handlers? They can be considered as triggers that execute JavaScript when something happens, such as click or move your mouse over a link, submit a form etc.

onClick onClick handlers execute something only when users click on buttons, links, etc. Let's see an example:

     <script>
     function ss()
     {
     alert("Thank you!");
     }
     </script>
     <form>
     <input type="button" 
	 value="Click here" onclick="ss()">
     </form>

The function ss() is invoked when the user clicks the button. Note: Event handlers are not added inside the <script> tags, but rather, inside the html tags.

onLoad The onload event handler is used to call the execution of JavaScript after loading:

     <body onload="ss()">
     <frameset onload="ss()">
     <img src="whatever.gif" onload="ss()">

onMouseover,onMouseout These handlers are used exclusively with links.

     <a href="#" 
        onMouseOver="document.write('Hi, nice to see you!">
        Over Here!</a>
     <a href="#" onMouseOut="alert('Good try!')">Get Out Here!</a>

onUnload onunload executes JavaScript while someone leaves the page. For example to thank users.

     <body onunload="alert('Thank you for visiting us. See you soon')">

Handle multiple actionsHow to have an event handler be able to call multiple functions/statements? That's simple. You just need to embed the functions inside the event handler as usual, but separate  each of them using a semicolon:

     <form>
     <input type="button" value="Click here!" onClick="alert('Thanks 
     for visiting my site!');window.location='http://www.yahoo.com'">
     </form>


  Back to Index Page
 Next Page:  

Embedding and including
write and writeln
Document object
Message box
Variables and Conditions
Function
Event handler
Form
Link
Date
Window
Frame


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech