Set cursor position in a input box - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Set cursor position in a 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 www  .jav a 2s. co  m*/
 console.log(event.charCode);
    if(event.charCode < 48 || event.charCode>57)
        event.preventDefault();
}

      </script>  
   </body>
</html>

Related Tutorials