Click to See Complete Forum and Search --> : edit box


swstos
04-02-2003, 07:13 PM
Hi...

i have an edit box that must take only integers...
Is it possible to do it useing javascript???

currently when a user types anything that is not an integer and click on the submit button it displays a message saying that must type only integers... but i dont want to do it that way, i want to not allow the user to enter letters... or even when the user stop typing letters the edit box will display an error message...? is that possible

Any help will be appreciated

Thanks in advance.

mutus
04-02-2003, 07:37 PM
I personally don't like disabling the user's keyboard...but it can be done.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function checkNum(evt){
var chCode = (evt.which)?evt.which:evt.keyCode;
if (document.getElementById&&!document.all){
if ((evt.charCode>34 && evt.charCode<41) || evt.charCode==46) return false;
if ((chCode>34 && chCode<41) || chCode==46) return true;
}
if(chCode>31 && (chCode<48 || chCode>57)){
return false;
}
return true;
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form><input type="text" name="textfield" onKeyPress="return checkNum(event);"></form>
</body>
</html>

swstos
04-02-2003, 07:43 PM
thanks for the help...

but can u please tell me why is not good idea to disable the user's keyboard??? Is it but design?