onkeydown and onkeyup events not working in JavaScript... Is it just me or is it deprecated? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

onkeydown and onkeyup events not working in JavaScript... Is it just me or is it deprecated?

Im trying to use onkeyup and onkeydown events but they just won't fire. Only the keypress event works but i also want to know when the key is released. Are there any alternatives?

6th Feb 2019, 2:43 PM
Slightly Epic
Slightly Epic - avatar
2 Answers
0
<html> <body> <p>A function is triggered when the user is pressing a key in the input field.</p> <input type="text" onkeydown="myFunction()"> <script> function myFunction() { alert("You pressed a key inside the input field"); } </script> </body> </html>
6th Feb 2019, 6:57 PM
Syed Mustafa Hussain
Syed Mustafa Hussain - avatar
0
<html> <body> <p>A function is triggered when the user is pressing a key in the input field.</p> <input type="text" onkeypress="myFunction()"> <script> function myFunction() { alert("You pressed a key inside the input field"); } </script> </body> </html>
6th Feb 2019, 6:57 PM
Syed Mustafa Hussain
Syed Mustafa Hussain - avatar