Tuesday, January 8, 2013

Numeric Values only in html text inputs

This code will allow only numeric values to be inputted in the textbox.

Sample Source Code:


<html>
   <head>
      <script language=Javascript>
     
         function getInput(evt) {
           var ascII = (evt.which) ? evt.which : event.keyCode;
           if (ascII < 48 || ascII > 57)
               return false;
   return true;
         }

      </script>
  </head>
  <body>
You can input numeric values only: <br>
    <input type="text" onkeypress="return getInput(event)" />
  </body>
</html>