To Display Alert for Incompatible Input

by deva 2007-05-29 15:49:40

Hi,

Consider an input text box in the browser, which has to get only numeric inputs. When non-numeric input given, it should pop-up a warning. Consider the following javascript code to make this.
 
<html>
<head>
<script language=javascript>
function numcheck()
{
var val=document.myform.fontsize.value;
var valstr=val.toString();
for(i=0; i<=valstr.length-1; i++)
{
var asci=valstr.charCodeAt(i);
if (asci < 48 || asci > 57)
{
alert("Please enter values from 0 to 255 only");
document.myform.fontsize.value="";
break;
}
}
}

</script>
</head>

<body>
<form name=myform>
Enter Number: <input type=text name=fontsize value="35" onKeyUp=numcheck()>
</form>
</body>
</html>

Tagged in:

4081
like
0
dislike
0
mail
flag

You must LOGIN to add comments