onkeyup Event

Example

Call a function when the user releases a key:

<input type="text" onkeyup="myFunction()">
Try it Yourself »

More examples below.


Description

The onkeyup event occurs when the user releases a key on the keyboard.

Keyboard Events

EventOccurs When
onkeydownThe user presses a key
onkeypressThe user presses a key
onkeyupthe user releases a key

See Also:

The Keyboard Event Object

Warning

The onkeypress event is deprecated.

It is not fired for all keys (like ALT, CTRL, SHIFT, ESC) in all browsers.

To detect if the user presses a key, always use the onkeydown event. It works for all keys.



Syntax

In HTML:

<element onkeyup="myScript">
Try it Yourself »

In JavaScript:

object.onkeyup = function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("keyup", myScript);
Try it Yourself »

Technical Details

Bubbles: Yes
Cancelable: Yes
Event type: KeyboardEvent
HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>
DOM Version: Level 2 Events

More Examples

Example

Using "onkeydown" together with the "onkeyup" event:

<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Try it Yourself »

Example

Output the actual key that was released inside a text field:

Enter your name: <input type="text" id="fname" onkeyup="myFunction()">

<script>
function myFunction() {
  var x = document.getElementById("fname").value;
  document.getElementById("demo").innerHTML = x;
}
</script>
Try it Yourself »

Browser Support

onkeyup is a DOM Level 2 (2001) feature.

It is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.