0% found this document useful (0 votes)
121 views

Write A Program To Design A Form and Handle Any 2 Mouse Events

The document contains code to handle mouse and key events in JavaScript. The first example creates a form that handles the onmouseover and onmouseout events on a paragraph of text, displaying messages when each event occurs. The second example handles the onkeydown and onkeypress events on text input fields, changing the background color on keydown and displaying an alert on keypress.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Write A Program To Design A Form and Handle Any 2 Mouse Events

The document contains code to handle mouse and key events in JavaScript. The first example creates a form that handles the onmouseover and onmouseout events on a paragraph of text, displaying messages when each event occurs. The second example handles the onkeydown and onkeypress events on text input fields, changing the background color on keydown and displaying an alert on keypress.

Uploaded by

sakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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