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
Online Degrees Scholarships & Fellowships Internships Student Financial Aid Study Abroad Itech Bookstore
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
ASP.NET
SQL
AJAX
FTP
XML
Career Center
Job List
Web Jobs
Student Jobs
Computer Jobs
Engineer Jobs
Developer Jobs
Job Search
Resume Writing
Job Interview
Salary Info


itech > 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
Message boxt
Variables and Conditions
Variables and Conditionst
Function
Event handler
Form
Link
Date
Window
Frame
 

JavaScript Books
JavaScript Jobs



Bookmark:  del.icio.us digg facebook Reddit Mixx BlinkList Fark Furl NewsVine Simpy Spurl Segnalo Technorati blogmarks Google YahooMyWeb Windows Live



JavaScript Course: Event handler - www.itechcollege.com
Copyright ©2008, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech