Linggo, Marso 6

Javascript Input Numbers Only

This simple javascript code allows you to trap errors on textbox.
It allows the user to input numbers only on a certain text boxes. Symbols and letters are not allowed.

Add this attribute to the textbox you want to input numbers only.

onkeypress="return isNumberKey(event)"

isNumberKey(event) is the name of your javascript function.

You can put this code either on the head section or on the last part of you codes. It will still function.

<script language="javascript" >
 function isNumberKey(evt)
 {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
 }  
</script>

0 comments:

Mag-post ng isang Komento

 
Powered by Blogger