Events
<a href="http://www.w3.org"
onMouseOver="alert('please stay')">
Visit the W3
</a>
• Notice that the onClick attribute requires us to use double quotes (" ") around
our JavaScript code, so when we need quote marks for the alert, we use single
quotes (' ') to avoid possible errors.
<html><head>
<script language="JavaScript">
<!—
function hi_and_bye() {
window.alert('Hi!'); window.alert('Bye!');
}
//-->
</script>
<body>
<a href="http://www.yahoo.com"
onClick="hi_and_bye();">Yahoo!</a>
</body></html> Demo
Rollover Images
<html>
<body onUnload="window.alert('Please come
back later');">
<b>Text for the body of the page</b><br>
<a href="http://www.yahoo.com">Yahoo</a>
</body></html>
Demo
onFocus Examples
• onFocus in form
<html><body>
<form>
Enter your name:
<input type="text" onFocus="window.alert('Don\'t forget
to capitalize!');">
</form>
</body></html>
Demo
• onFocus in window
<html>
<body onfocus="window.alert('thank you for choosing
this window');">
<h1>Hello 1</h1>
</body>
</html>
Demo
onBlur Example
<html>
<body>
<form>
Give this box focus:<br>
<input type="text"
onBlur="window.alert('Please come back!');">
<br>
Then give this box focus to blur the 1st one:<br>
<input type="text">
</form>
</body>
</html>
Demo
<html><body>
<form onsubmit="window.alert('Thank you');">
What is your name?<br>
<input type="text" name="thename"><br>
<input type="submit">
</form>
</body></html>
Demo
<form>
<input type="button" value="Go Searching!"
onClick="window.location='http://www.yahoo.com';">
</form>