WT Practical 8


Practical : 8
Subject : Web Technology

Aim : Write a JavaScript that handles following mouse events Add necessary elements.
  • JavaScript gives the key code for the key pressed.
  • When the key is released background should change to blue.

Source Code :
  • i)
<!DOCTYPE html>
<html>
<head>
            <title>partik008</title>
</head>
<body>
<input type="text" size="1" onkeypress="uniCharCode(event)"
onkeydown="uniKeyCode(event)">
<p>onkeypress - <span id="onkeypress"></span></p>
<p>onkeydown - <span id="onkeydown"></span></p>
<script>
function uniCharCode(event) {
var char = event.which || event.keyCode;
document.getElementById("onkeypress").innerHTML = "The Unicode CHARACTER code is: "+char;
}
function uniKeyCode(event) {
var key = event.keyCode;
document.getElementById("onkeydown").innerHTML = "The Unicode KEY code is: "+key;
}
</script>
</body>
</html>
  • ii)
<!DOCTYPE html>
<html>
<head>
            <title>pratik008</title>
</head>
<body>
<form>
<input id="pr" type="text" onkeydown="changetext()" onkeyup="changebg()">
</form>
<script>
function changetext()
{
document.getElementById("pr").style.backgroundColor = "lightblue";
}
function changebg()
{
document.body.style.backgroundColor = "#ccffff";
}
</script>
</body>
</html>

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment