Prevent a user from entering text in a text area
Hello, I have a text area, I want that user's should not be able to enter a charaters in it. I want them to enter only numbers.
I have written the code below to do this but it is not working as I think I am not calling the function right way: can anyone rectify my code:
Code:
<html>
<head>
<script type="text/javascript">
function CheckNumeric()
{
// Get ASCII value of key that user pressed
var key = window.event.keyCode;
// Was key that was pressed a numeric character (0-9)?
if ( key > 47 && key < 58 )
return; // if so, do nothing
else
window.event.returnValue = null; // otherwise,
// discard character
}
</script>
</head>
<body>
<input type="text" name="text" value=""></input>
<input type="button" name="button1" value="Check" onclick="return CheckNumeric();"></input>
</body>
</html>
I am open to new suggestions as well, if I can show some alert to user if they enter character rather than no.
your help is welcome