i2tutorials

Javascript Keyboard Events

Javascript Keyboard Events

 

Javascript events that occur when the user presses a key on the keyboard, belong to the KeyboardEvent Object.

 

Event                                Description

onkeydown                       The user is pressing a key.

onkeypress                        The user presses a key.

onkeyup                             The user releases a key.

 

EXAMPLE:


<!DOCTYPE html>
<html>
<body>

<p>The function transforms the character to upper case.</p>
Enter your name: <input type="text" id="fname" onkeyup="myFunction()">

<script>
function myFunction() {
 var x = document.getElementById("fname");
 x.value = x.value.toUpperCase();
}
</script>

</body>
</html>

 

OUTPUT:

 

Javascript Keyboard Events

 

 

Exit mobile version