You are on page 1of 27

Mouse over:

<html>
<head>
<script language="JavaScript">
function function1(){
alert('The '+event.type+' event on.')
}
</script>
</head>
<body>
<div id="myDiv" onmouseover="function1()">
The mouseover event.
</div>
</body>
</html>
Output:
On abort:

<html>
<head>
<script language="JavaScript">
function function1() {
alert("The loading action has been aborted\nTry again later")
}
</script>
</head>
<body>
<img src="http://www.java2s.com/style/logo.png" onabort="function1()">
</body>
</html>
Output:
OnBlur:

<html>
<head>
<script language="JavaScript">
function function1() {
window.open("http://www.java2s.com", "", "");
}
</script>
</head>
<body>
Press the Tab key to set focus on the link below.<br>
<a id="myL" href="http://www.java2s.com/" target=_blank onBlur="function1()">
java2s.com
</a>
<br>
Now press the Tab key again to move focus to another element.
</body>
<html>
Output:
Onchange:

<html>
<head>
<script language="JavaScript">
function function2(colors) {
var col = (colors.options[colors.selectedIndex].value);
if (col) {
document.bgColor = col;
}
alert("The background color has changed to "+col)
}
</script>
</head>
<body>
<select name="colors" onChange="function2(this)">
<option value="white" selected>White</option>
<option value="cyan">Cyan</option>
<option value="ivory">Ivory</option>
</select>
</body>
</html>
Output:
On click:

<html>
<body>
<input type="text"
name="textfield"
onclick="alert('You clicked an input text field')"
value="Click me">
</body>
</html>
Output:
On error:

<html>
<head>
<script language="JavaScript">
window.onerror = alert("Errors")
</script>
</head>
<body>
</body>
</html>
Output:
On focus:
<html>
<head>
<script language="JavaScript">
function function1() {
document.getElementById("myL").blur();
alert("Element has received focus.");
window.open("http://www.java2s.com", "", "");
}
</script>
</head>
<body>
<a id="myL"
href="http://www.java2s.com/"
target=_blank
onFocus="function1()">
java2s.com
</a>
</body>
</html>
Output:

(By entering tab once.)


(Clicking on OK button)
On load:

<html>
<body onLoad="alert('The document is loaded')">
<img src="http://www.java2s.com/style/logo.png">
</body>
</html>
Output:
On mouse out:

<html>
<head>
<script language="JavaScript">
function function1(){
alert('The '+event.type+' event fired')
}
</script>
</head>
<body>
<div id="myDiv" onmouseout="function1()">
Move the mouse over and out this div element area.
</div>
</body>
</html>
Output:
On reset:

<html>
<body>
<p>Input some text below and click the reset button.</p>
<form name="form1"
method="post"
action="" onreset="alert('The form is being reset')">
<input type="text" value="">
<input type="reset" value="Reset">
</form>
</body>
</html>
Output:
On select:

<html>
<body onselect="alert('The user is selecting some body object')">
Hightlight me to triger the onselect event
</body>
</html>
Output:
On submit:

<html>
<body>
<form name="form1"
method="post"
action=""
onsubmit="alert('The form is being submitted')">
<input type="text" name="textfield">
<input type="submit" value="Submit">
</form>
</body>
</html>
Output:
On unload:

<html>
<body onunload="alert('Exiting the page!')">
</body>
</html>
Output:

Press restart button on windows

You might also like