+ 1

How i recognize enter key is pressed using JavaScript

9th Jul 2018, 2:40 AM
Saurabh Kasaudhan
Saurabh Kasaudhan - avatar
6 Réponses
+ 4
e.which is more reliable than e.keyCode when it comes to compatibility if you're using jQuery. just my 2c
9th Jul 2018, 6:00 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
Saurabh Kasaudhan Use" e.which" insteadof "e.keyCode" as Jonathan Pizarra said.
9th Jul 2018, 7:11 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
<script> <input id="area" type="text" onkeypress="return run(event)" /> </script> function run(e) { if (e.keyCode == 13) { var test = document.getElementById("area").value; alert (test) } } may not work on some device's because of Placing "Enter" key in different places so you have to find the keycode of your keyboard
9th Jul 2018, 3:12 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
<input onkeydown="console.log('key is pressed')"; />
9th Jul 2018, 3:08 AM
Calviղ
Calviղ - avatar
0
ok
9th Jul 2018, 7:13 AM
Saurabh Kasaudhan
Saurabh Kasaudhan - avatar