JavaScript Key Event

This page discusses - JavaScript Key Event

JavaScript Key Event

JavaScript onkeyup Event


This section illustrates you the use of onkeyup event in JavaScript.

In the given example, we are going to show you how to display the text of textField1 on the text field2 on key up. For this purpose, we have created two text fields text1 and text2. On pressing the key to write the text on the textbox1, you will see that the same text will start displaying on the textbox2. This is possible by using the onkeyup event. It occurs when a keyboard key is released.

Following code copies the value of textbox 1 to textbox2:

document.form.text2.value = document.form.text1.value;

Here is the code:

<h2>TextBox shows Key Event</h2>
<script language="JavaScript">
function display() {
document.form.text2.value = document.form.text1.value;
<form name="form">
TextBox1: <input type="textbox" id="text1" onkeyup="display();"><br>
TextBox1: <input type="textbox" id="text2" >

Output will be displayed as:

Download Source Code: