JavaScript Events
The change in the state of an object is known as an Event. In html, there are various events
which represents that some activity is performed by the user or by the browser.
Mouse events:
Event Performed Event Handler Description
click onclick When mouse click on an element
mouseover onmouseover When the cursor of the mouse comes over the element
mouseout onmouseout When the cursor of the mouse leaves an element
mousedown onmousedown When the mouse button is pressed over the element
mouseup onmouseup When the mouse button is released over the element
mousemove onmousemove When the mouse movement takes place.
Keyboard events:
Event Performed Event Handler Description
Keydown & Keyup onkeydown & onkeyup When the user press and then release the key
Form events:
Event Event Description
Performed Handler
focus onfocus When the user focuses on an element
submit onsubmit When the user submits the form
blur onblur When the focus is away from a form element
change onchange When the user modifies or changes the value of a form
element
Example No. 1.
<html>
<body>
<script language="Javascript" >
function clickevent()
{
document.write("Students of BCA Class");
}
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
</html>
Example 2.Note: Kindly change image names as per availability on your device.
<html>
<head>
<script language="javascript">
function Mouseover()
{
document.a1.src = "Jellyfish.jpg";
}
function Mouseout()
{
document.a1.src = "Desert.jpg";
}
</script>
</head>
<body>
<img name="a1" src="Desert.jpg" width="650px" height="550px"
onMouseOver="Mouseover()" onMouseOut="Mouseout()">
</body>
</html>