You are on page 1of 3

Practical 8

/* 1. Write a program to design a form and handle any 2 mouse


Events */

<html>
<body>
<script lang="Javascript" type="text/javascript">

//mouseOver
function mouseOver()
{
document.getElementById("output").innerHTML +=
"<b><br>MouseOver Event</b><br>";
}

//mouseOut
function mouseOut()
{
document.getElementById("output").innerHTML +=
"<b>MouseOut Event</b>";
}
</script>

<br><b>onmouseover and mouseout</b> <br>


<p id="para" onmouseover="mouseOver()"
onmouseout="mouseOut()">Hover over this
Text !!!</p>
<b id="output"></b>
</body>
</html>
Practical 8

/* 2. Write a program to design a form and handle any 2 Key


Events */

<html>
<body>
<script lang="Javascript" type="text/javascript">
function keydown_event()
{ document.getElementById("demo").style.
backgroundColor = "red";
}

function keypress_event()
{ alert("You pressed a key inside the
input field");
}

</script>

<h4>onkeydown</h4>
<p>This example demonstrates how to assign an
<b>"onkeydown"</b> event to an input <br>
Practical 8

Press a key inside the text field to set a red


background color.</p>
<input type="text" id="demo"
onkeydown="keydown_event()"> <br><br>

<h4>onkeypress</h4>
<p>A function is triggered when the user is
pressing a key in the input field.</p>
<input type="text" onkeypress="keypress_event()">
<br><br>
</body>
</html>

You might also like