HTML event attribute onkeyup

The onkeyup attribute event is triggered when the user pressed a key.

The order of events related to the onkeydown event:

  • onkeydown
  • onkeypress
  • onkeyup

What's new in HTML5



<element onkeyup="script or Javascrpt function name">

Supported Tags

All HTML elements, EXCEPT:


Browser compatibility

onkeyup Yes Yes Yes Yes Yes


<!DOCTYPE html>
<!--  ww w.  j a  v  a2 s  . c  om-->
<input type="text" onkeyup="myFunction()">

function myFunction() {
    console.log("pressed a key");


Click to view the demo

Example 2

Listen to key up event for TextArea in JavaScript

<script type="text/javascript">
  function handleEvent(oEvent) {<!-- www  . j  av a2  s .c  om-->
    var oTextbox = document.getElementById("txt1");
    oTextbox.value += "\n>" + oEvent.type;
  <P>Type some characters into the first textbox.</p>
    <textarea id="txtInput" rows="15" cols="50"
      onkeydown="handleEvent(event)" onkeyup="handleEvent(event)"
    <textarea id="txt1" rows="15" cols="50"></textarea>

Click to view the demo