<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> <head> <title>JavaScript Events</title> <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta name="Keywords" content="OS, DOS,XML,tutorial,HTML,DHTML,CSS,XSL,XHTML,JavaScript,ASP,ADO,VBScript,DOM,C, C++, accounting, tally,Wings adobe, dreamweaver, photoshop,CORALDRAW,W3C,authoring,programming,learning,beginner's guide,primer,lessons,school,howto,reference,free,examples,samples,source code,demos,tips,links,FAQ,tag list,forms,frames,color tables,Cascading Style Sheets,Active Server Pages,Dynamic HTML,Internet database,windows,XP,windows 7,Doc,Excel,Power Point, development,CCNA, CCNP, MCSE, LINUX, Linux, Webbuilder,Sitebuilder,Webmaster,HTMLGuide,SiteExpert,CERTIFICATION,Microsoft Certified" /> <meta name="Description" content="HTML HTML5 OS LINUX MULTIMIDIA ACCOUNTING TALLY XHTML CSS CSS3 JavaScript XML XSL ASP SQL ADO VBScript Tutorials References Examples Microsoft Certified " /> <link rel="stylesheet" type="text/css" href="../shinetutorial.css" /> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-31077068-1']); _gaq.push(['_setDomainName', 'shinetutorial.com']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <!--[if gt IE 9]> <style type="text/css"> body { overflow-y:scroll; } </style> <![endif]--> <style type="text/css"> a.dark:link,a.dark:visited {text-decoration:none; color:#404040; background-color:transparent} a.dark:hover,a.dark:active {text-decoration:underline; color:#404040; background-color:transparent} .style1 { border-style: solid; } </style> </head> <body> <center> <table style="width:902px;margin-top:0px;margin-bottom:0px;background-color:#ffffff;" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <table width="890" border="0" cellpadding="0" cellspacing="0" style="margin-top:1px;background-color: #F0FFFF;border-bottom:1px solid black"> <tr style="height:47px"> <td width="15" style="width: 15px"> </td> <td width="663" valign="middle" style="text-align:left"><table width="98%" border="0"> <tr> <th width="43%" rowspan="2" scope="col"> <img style="margin-top:6px" border="0" src="../images/Shine%20h_logo.gif" width="279" height="81" alt="Shine Tutorial" title="Shine Tutorial" /></th> <th width="3%" scope="col"> </th> <th width="54%" scope="col"> </th> </tr> <tr> <td> </td> <td> <img src="../images/topimageside.gif" width="332" height="62" alt="shinetutorialtopsideimage" longdesc="http://www.shineuniversal.com" /></td> </tr> </table></td> <td width="207" align="right" valign="bottom"> <form style="font-size:10px;margin-bottom:10px;" method="get" name="searchform" action="../www.google.com/search/index.htm" target="_blank"> <table width="200" border="0" align="center"> <tr> <th style="width: 200 px; height: 31px" scope="col"> <div id="google_translate_element"></div><script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', multilanguagePage: true, gaTrack: true, gaId: 'UA-31077068-1', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script></th> </tr> </table> <form action="http://www.google.com" id="cse-search-box"> <div></div> </form> <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script> </form> </td> <td width="5"></td> </tr> </table> <table width="890" border="0" cellpadding="0" cellspacing="0" style="background-color:#6495ED"> <tr style="height:20px"> <td class="blacknav" style="border-left:none" width="50"><a class="m_item" href="../index.html">HOME</a></td> <td class="blacknav" width="40"><a href="../DOC/default.html" title="Disk Operating System" target="_top" class="m_item">DOS</a></td> <td class="blacknav" width="40"><a href="../os/default.html" title="Operating System" target="_top" class="m_item">OS</a></td> <td class="blacknav" width="45"><a href="../c&cc/default.html" title="Programming Language" target="_top" class="m_item">C,C++</a></td> <td class="blacknav" width="40"><a href="../html/default.html" title="HyperText Markup Language" target="_top" class="m_item">HTML</a></td> <td class="blacknav" width="40"><a href="../css/default.html" title="Cascading Style Sheets" target="_top" class="m_item">CSS</a></td> <td class="blacknav" width="40"><a href="../xml/default.html" title="Extensible Markup Language" target="_top" class="m_item">XML</a></td> <td class="blacknav" width="45"><a href="default.html" title="Programming Language, but some people say..... JAVA is "Just Another Virtual Application"" target="_top" class="m_item">JAVA</a></td> <td class="blacknav" width="40"><a href="../asp/default.html" title="Active Server Pages" target="_top" class="m_item">ASP</a></td> <td class="blacknav" width="40"><a href="../php/default.html" title="PHP used to stand for Personal Home Page. It was renamed to 'PHP: Hypertext Preprocessor" target="_top" class="m_item">PHP</a></td> <td class="blacknav" width="40"><a href="../sql/default.html" title="Structured Query Language" target="_top" class="m_item">SQL</a></td> <td class="blacknav" width="60"><a href="../office/default.html" title="Software Most Used in Offices" target="_top" class="m_item">OFFICE</a></td> <td class="blacknav" width="90"><a class="m_item" href="../multimidia/default.html" target="_top">MULTIMEDIA</a></td> <td class="blacknav" width="60"><a class="m_item" href="../more/default.html" target="_top">MORE...</a></td> <td class="blacknav" width="80"></td> <td class="blacknav" width="105"><a href="../certificates/default.html" title="Professional Certifications from Microsoft, Linux, Cisco and all IT exam" target="_top" class="m_item">CERTIFICATION</a></td> <td class="blacknav" style="border-right:none" width="50"><a class="m_item" href="../about/default.html" target="_top">ABOUT</a></td></table> <div style="width:900px;height:94px;position:relative;margin-left:auto;margin-right:auto;margin:0px;padding:0px;overflow:hidden; left: 0px; top: -3px;"> <div class="toprect_img"> <b>S T ADVT </b> <a target="_blank" rel="nofollow" href="http://www.shinetutorial.com/smalladvt/small004.html"><img src="../stadvt_img/advt_004.gif" alt="" width="160" border="0" style="position:absolute; left:0px; bottom:0px; height: 90px;" /></a><br /> </div> <div style="width:728px;height:90px;position:absolute;right:0px;top:0px;"> <iframe id="leaderframe" style="background-color:#ffffff;height:90px;width:728px" src="../stbanners/sttopleaderframe_0002.htm" height="90" width="728" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe> </div></div> <table style="margin-top:1px" width="890" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="150px" height="1325" valign="top" class="left_container"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <th height="13" class="left">TUTORIALS</th> </tr> <tr> <td class="left" align="left"><div style="margin-left:1px;margin-top:5px"> <h2 class="left"><span class="left_h2">JS</span> Basic</h2> <a target="_top" href="default.asp" >JS HOME</a><br /> <a target="_top" href="js_introduction.asp" >JS Introduction</a><br /> <a target="_top" href="js_howto.asp" >JS How To</a><br /> <a target="_top" href="js_whereto.asp" >JS Where To</a><br /> <a target="_top" href="js_statements.asp" >JS Statements</a><br /> <a target="_top" href="js_comments.asp" >JS Comments</a><br /> <a target="_top" href="js_variables.asp" >JS Variables</a><br /> <a target="_top" href="js_operators.asp" >JS Operators</a><br /> <a target="_top" href="js_comparisons.asp" >JS Comparisons</a><br /> <a target="_top" href="js_if_else.asp" >JS If...Else</a><br /> <a target="_top" href="js_switch.asp" >JS Switch</a><br /> <a target="_top" href="js_popup.asp" >JS Popup Boxes</a><br /> <a target="_top" href="js_functions.asp" >JS Functions</a><br /> <a target="_top" href="js_loop_for.asp" >JS For Loop</a><br /> <a target="_top" href="js_loop_while.asp" >JS While Loop</a><br /> <a target="_top" href="js_break.asp" >JS Break Loops</a><br /> <a target="_top" href="js_loop_for_in.asp" >JS For...In</a><br /> <a target="_top" href="js_events.asp" style='font-weight:bold;'>JS Events</a><br /> <a target="_top" href="js_try_catch.asp" >JS Try...Catch</a><br /> <a target="_top" href="js_throw.asp" >JS Throw</a><br /> <a target="_top" href="js_special_characters.asp" >JS Special Text</a><br /> <a target="_top" href="js_guidelines.asp" >JS Guidelines</a><br /> <br /> <h2 class="left"><span class="left_h2">JS</span> Objects</h2> <a target="_top" href="js_obj_intro.asp" >JS Objects Intro</a><br /> <a target="_top" href="js_obj_string.asp" >JS String</a><br /> <a target="_top" href="js_obj_date.asp" >JS Date</a><br /> <a target="_top" href="js_obj_array.asp" >JS Array</a><br /> <a target="_top" href="js_obj_boolean.asp" >JS Boolean</a><br /> <a target="_top" href="js_obj_math.asp" >JS Math</a><br /> <a target="_top" href="js_obj_regexp.asp" >JS RegExp</a><br /> <br /> <h2 class="left"><span class="left_h2">JS</span> Advanced</h2> <a target="_top" href="js_browser.asp" >JS Browser</a><br /> <a target="_top" href="js_cookies.asp" >JS Cookies</a><br /> <a target="_top" href="js_form_validation.asp" >JS Validation</a><br /> <a target="_top" href="js_animation.asp" >JS Animation</a><br /> <a target="_top" href="js_image_maps.asp" >JS Image Maps</a><br /> <a target="_top" href="js_timing.asp" >JS Timing</a><br /> <a target="_top" href="js_objects.asp" >JS Create Object</a><br /> <a target="_top" href="js_summary.asp" >JS Summary</a><br /> <br /> <h2 class="left"><span class="left_h2">JS</span> Examples</h2> <a target="_top" href="js_examples.asp" >JS Examples</a><br /> <a target="_top" href="js_ex_objects.asp" >JS Objects Examples</a><br /> <a target="_top" href="js_ex_browser.asp" >JS Browser Examples</a><br /> <a target="_top" href="js_ex_dom.asp" >JS HTML DOM Examples</a><br /> <a target="_top" href="js_quiz.asp" >JS Quiz</a><br /> <a target="_top" href="js_exam.asp" >JS Exam</a><br /> <br /> <h2 class="left"><span class="left_h2">JS</span> References</h2> <a target="_top" href="../jsref/default.asp" >JavaScript Objects</a><br /> <a target="_top" href="../jsref/default.asp" >HTML DOM Objects</a> <h2 class="left"><br /> </h2> </div> <p> <br /> </p></td></tr></table> </td> <td width="6px"> </td> <td valign="top" align="left"><table style="background-color:#ffffff;color:#000000;padding-bottom:8px;padding-right:5px" width="574" border="0" cellpadding="0" cellspacing="0"> <tr> <td style="padding-top:4px"> <h1>JavaScript <span class="color_h1">Events</span></h1> <table class="chapter" border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="prev"><a class="chapter" href="js_loop_for_in.asp">« Previous</a></td> <td class="next"><a class="chapter" href="js_try_catch.asp">Next Chapter »</a></td> </tr> </table> <hr /> <p class="intro">Events are actions that can be detected by JavaScript.</p> <hr /> <h2>Events</h2> <p>By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript.</p> <p>Every element on a web page has certain events which can trigger a JavaScript. For example, we can use the onClick event of a button element to indicate that a function will run when a user clicks on the button. We define the events in the HTML tags.</p> <p>Examples of events:</p> <ul> <li>A mouse click</li> <li>A web page or an image loading</li> <li>Mousing over a hot spot on the web page</li> <li>Selecting an input field in an HTML form</li> <li>Submitting an HTML form</li> <li>A keystroke </li> </ul> <p><b>Note:</b> Events are normally used in combination with functions, and the function will not be executed before the event occurs!</p> <p>For a complete reference of the events recognized by JavaScript, go to our complete <a href="../jsref/default.asp">JavaScript reference</a>.</p> <hr /> <h2>onLoad and onUnload</h2> <p>The onLoad and onUnload events are triggered when the user enters or leaves the page.</p> <p>The onLoad event is often used to check the visitor's browser type and browser version, and load the proper version of the web page based on the information.</p> <p>Both the onLoad and onUnload events are also often used to deal with cookies that should be set when a user enters or leaves a page. For example, you could have a popup asking for the user's name upon his first arrival to your page. The name is then stored in a cookie. Next time the visitor arrives at your page, you could have another popup saying something like: "Welcome John Doe!".</p> <hr /> <h2>onFocus, onBlur and onChange</h2> <p>The onFocus, onBlur and onChange events are often used in combination with validation of form fields.</p> <p>Below is an example of how to use the onChange event. The checkEmail() function will be called whenever the user changes the content of the field:</p> <table class="code" cellspacing="0" cellpadding="0" border="0" width="100%"> <tr> <td><input type="text" size="30" id="email" onchange="checkEmail()"></td> </tr> </table> <br /> <hr /> <h2>onSubmit</h2> <p>The onSubmit event is used to validate ALL form fields before submitting it.</p> <p>Below is an example of how to use the onSubmit event. The checkForm() function will be called when the user clicks the submit button in the form. If the field values are not accepted, the submit should be cancelled. The function checkForm() returns either true or false. If it returns true the form will be submitted, otherwise the submit will be cancelled:</p> <table class="code" cellspacing="0" cellpadding="0" border="0" width="100%"> <tr> <td><form method="post" action="xxx.htm" onsubmit="return checkForm()"></td> </tr> </table> <br /> <hr /> <h2>onMouseOver and onMouseOut</h2> <p>onMouseOver and onMouseOut are often used to create "animated" buttons.</p> <p>Below is an example of an onMouseOver event. An alert box appears when an onMouseOver event is detected:</p> <table class="code" cellspacing="0" cellpadding="0" border="0" width="100%"> <tr> <td><a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver event');return false"><img src="w3s.gif" alt="W3Schools" /></a></td> </tr> </table> <br /> <table class="chapter" border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td class="prev"><a class="chapter" href="js_loop_for_in.asp">« Previous</a></td> <td class="next"><a class="chapter" href="js_try_catch.asp">Next Chapter »</a></td> </tr> </table></td></tr> </table> <table width="100%" border="0"> <tr> <th scope="col"> </th> <th scope="col"> </th> </tr> <tr> <th width="61%" scope="col"><strong> <iframe id="T2" style="background-color:#ffffff; height:282px; width:340px; text-align: center;" src="../stbanners/stcubeleaderframe_0003.htm" height="282" width="340" marginwidth="1" marginheight="1" frameborder="0" scrolling="No" name="T3"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe> </strong></th> <th width="39%" scope="col"><strong> <iframe id="T4" style="background-color:#ffffff; height:282px; width:195px; text-align: left;" src="../stbanners/stcubeleaderframe_0002.htm" height="282" width="195" marginwidth="1" marginheight="1" frameborder="0" scrolling="No" name="T3"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe> </strong></th> </tr> <tr> <td> </td> <td> </td> </tr> </table> <h2 class="tutheader"><strong> <iframe id="T5" style="background-color:#ffffff; height:250px; width:575px; text-align: left;" src="../stbanners/strrectangleleaderframe_0003.htm" height="250" width="575" marginwidth="1" marginheight="1" frameborder="0" scrolling="No" name="T3"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe> </strong><br /> </h2></td> <td style="width: 6px"> </td> <td class="right_container" valign="top" width="150px"> <table class="right" style="margin-top:0px" width="100%" cellpadding="0" cellspacing="0"> <tr><th class="right"> <form action="http://www.google.com" id="cse-search-box"> <div> <input type="hidden" name="cx" value="partner-pub-2518397126694060:9432236351" /> <input type="hidden" name="ie" value="UTF-8" /> <input type="text" name="q" size="20" /> <input type="submit" name="sa" value="Search" /> </div> </form> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script> <script type="text/javascript" src="http://www.google.com/cse/t13n?form=cse-search-box&t13n_langs=en"></script> <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script> <script type="text/javascript" src="http://www.google.com/cse/query_renderer.js"></script> <div id="queries"></div> <script src="http://www.google.com/cse/api/partner-pub-2518397126694060/cse/9432236351/queries/js?oe=UTF-8&callback=(new+PopularQueryRenderer(document.getElementById(%22queries%22))).render"></script> <iframe id="T3" style="background-color:#ffffff;height:600px; width:160px" src="../stbanners/strightleaderframe_0001.htm" height="90" width="728" marginwidth="1" marginheight="1" frameborder="0" scrolling="no" name="T3"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe> </th></tr> <tr> <td class="right" valign="top" align="center"><br /> </td></tr></table> <table class="right" width="100%" cellpadding="0" cellspacing="0"> <tr><th class="right"><iframe id="T" style="background-color:#ffffff;height:600px; width:160px" src="../stbanners/strightleaderframe_V0002.htm" height="600" width="160" marginwidth="1" marginheight="1" frameborder="0" scrolling="No" name="T3"> Your browser does not support inline frames or is currently configured not to display inline frames. </iframe></th></tr> <tr> <td class="right" valign="top" align="center"> </td></tr></table> <table class="right" width="100%" cellpadding="0" cellspacing="0"> <tr><th class="right" style="height: 13px"></th></tr> <tr> <td class="right" valign="top" align="center"> </td></tr></table></td></tr></table> <table id="footer" align="center" border="0" width="890" class="style1"> <tr> <td align="left" width="654"> </td> <td width="224" align="right" style="word-spacing:6px;font-size:90%;padding-right:10px;"><a href="../default.html" target="_top">HOME</a> | <a href="../forum/default.html" target="_blank">FORUM</a> | <a href="../about/default.html" target="_top">ABOUT</a></td> </tr> <tr> <td valign="top" colspan="2" align="center" style="padding-top:10px; text-align: center;">Shine Tutorial is only for training . We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. <br /> Our training materials are our own resemblance with the materials of any book, Institution or organization is not our responsibility .<br /> While using this site, you will have to agree that you read and accepted out terms & conditions and privacy policies. <br /> <img src="../copyright.JPG" width="328" height="24" alt="Copyright 1996-2013 Shine Tech. All Rights Reserved." /></td></tr></table> </td></tr></table> </center> </body> </html>