Javascript examples for DOM HTML Element:Form Event
Check key code for input box
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <input type="text" onkeypress="acceptText()"> <script type="text/javascript"> function acceptText(){//from w ww .ja v a2 s. c o m console.log(event.charCode); if(event.charCode < 48 || event.charCode>57) event.preventDefault(); } </script> </body> </html>