|
JavaScript : Events
Events are action initiated either by the user or the computer. An example
of a user event is any mouse movement or a keystroke. Every element
on a web page has certain events which can trigger a JavaScript.
Events are normally used in combination with functions, and the function
will not be executed before the event occurs
JavaScript defines five types of events which are form, image, image map,
link, and window events. Events are associated with HTML tags.
| Form Events |
| blur | The input focus was lost. |
| change | An element lost the focus since it was changed. |
| focus | The input focus was obtained. |
| reset | The user reset the object, usually a form. |
| select | Some text is selected. |
| submit | The user submitted an object, usually a form. |
<form method="post" action="myfile.htm" onsubmit="return ValidForm()">
| Window Events |
| blur | The input focus was lost. |
| error | An error occurred. |
| focus | The input focus was obtained. |
| load | The object was loaded. |
| unload | The object was exited. |
<html>
<head>
<script type="text/javascript">
<!--
function HelloWorld() {
alert("Hello World")
}
//-->
</script>
</head>
<body onload="HelloWorld()">
<p> onLoad Example
</body>
</html>
| Link Events |
| click | An object was clicked. |
| mouseOut | The mouse is moved from on top a link. |
| mouseOver | The mouse is moved over a link. |
<html>
<head>
<script type="text/javascript">
function Msg(){
alert("You Clicked Me")
}
</script>
</head>
<body>
<form>
<input type="button" onclick="Msg()" value="Click Me" />
</form>
</body>
</html>
| Image Events |
| abort | A user action caused an abort. |
| error | An error occurred. |
| load | The object was loaded. |
| Image Map Events |
| mouseOut | The mouse is moved from on top a link. |
| mouseOver | The mouse is moved over a link. |
|