---
title: "Implementing onkeypress event in Java Script"  
description: "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 whe"  
author: "Anonymous User"  
published: 2011-03-16  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/502/implementing-onkeypress-event-in-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# 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](https://www.mindstick.com/mindstickarticle/606dc00b-0f5b-4d5e-ad7b-174b6cb33423/images/ca7791b3-3f68-45ea-929e-a67453371bb7.png)

![onkeypress event in Java Script](https://www.mindstick.com/mindstickarticle/606dc00b-0f5b-4d5e-ad7b-174b6cb33423/images/091dc04f-70d7-43d6-aa5a-65ea281d9b94.png)

---

Original Source: https://www.mindstick.com/articles/502/implementing-onkeypress-event-in-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
