Posted By

pablazo on 02/07/07


Tagged

javascript input forms keyevent


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ironcrema


solo numeros en campo de texto javascript


 / Published in: JavaScript
 

URL: http://www.cambiaresearch.com/c4/029c978b-aac5-472e-97a8-95b256f5febd/How-Can-I-Use-Javascript-to-Allow-Only-Numbers-to-Be-Entered-in-a-TextBox.aspx

  1. <HTML>
  2. <HEAD>
  3. <SCRIPT language=Javascript>
  4. <!--
  5. function isNumberKey(evt)
  6. {
  7. var charCode = (evt.which) ? evt.which : event.keyCode
  8. if (charCode > 31 && (charCode < 48 || charCode > 57))
  9. return false;
  10.  
  11. return true;
  12. }
  13. //-->
  14. </SCRIPT>
  15. </HEAD>
  16. <BODY>
  17. <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">
  18. </BODY>
  19. </HTML>

Report this snippet  

You need to login to post a comment.