I have this simple HTML document
<input type="text" id="my_text" onkeypress="valid_numbers(event);" size="30"/>
<script type="javascript">
function valid_numbers(e)
{
var key=e.which || e.KeyCode;
if ( key >=48 && key <= 57)
// to check whether pressed key is number or not
return true;
else return false;
}
</script>
What I want is:
onkeypress of my_text
if the pressed key is number allow otherwise deny writing of the character.
But the above code doesn't work, my_text
element accept any character, what is wrong with the above code ?!..
Help Please!..