Javascript examples for DOM Event:which
Check key code in key event handler
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar"> <script type="text/javascript"> function isNumberKey(evt) {//from w w w .jav a2s .c om var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; else return true; } </script> </body> </html>