onkeyup Event
Definition and usage
The onkeyup event occurs when the user releases a key (on the keyboard).
Tip:Event order related to the onkeyup event:
Example
Example 1
Execute JavaScript when the user releases a key:
<input type="text" onkeyup="myFunction()">
Example 2
Use "onkeydown" and "onkeyup" events together:
<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Example 3
Output the actual key released in the 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>
Syntax
In HTML:
<element onkeyup="myScript">
In JavaScript:
object.onkeyup = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("keyup", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.
Technical details
Bubbling: | Support |
---|---|
Cancellable: | Support |
Event types: | KeyboardEvent |
Supported HTML tags: | All HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title> |
DOM Version: | Level 2 Events |
Browser Support
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onkeyup | Support | Support | Support | Support | Support |