Check key code for input box - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Check key code for input box

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials