Home > DeveloperSection > Articles > Implementing onkeypress event in Java Script

Implementing onkeypress event in Java Script


JavaScript JavaScript 
Ratings:
0 Comment(s)
 5030  View(s)
Rate this:

Implementing onkeypress event in Java Script

onkeypress event is called when ever any key is pressed in control. Normally we use onkeypress event to check that which key is pressed by user or when we want to make key logger type application. The following section gives you a simple demonstration in which we can use concept of onkeypress event in java script. Write down following code to create a user interface in java script.

Create an user interface in html

<body>

    <p><textarea id="TextArea1" cols="20" name="S1" rows="2" onkeypress="copyText()"></textarea></p>

    <p><textarea id="TextArea2" cols="20" name="S2" rows="2"></textarea></p>

</body>

Create a method in java script and call this method at onkeypress event

<script type="text/javascript">

        function copyText() {

            TextArea2.value = TextArea1.value;

        }

</script>

Output of the following code snippet is as follows

onkeypress event in Java Script

onkeypress event in Java Script


Don't want to miss updates? Please click the below button!

Follow MindStick