Here are 2 simple functions to validate the entry of a whole number or a numeric value that includes decimals.
HTML Code:
<html>
<head>
<script>
function wholenum(fieldwval){
wholeval=fieldwval.value;
if (wholeval != parseInt(wholeval)){
alert(wholeval + ' is not a whole number');
testform.whole.name.select();
testform.whole.name.focus();
}
}
function numfield(fieldval){
numval=fieldval.value;
if (numval != parseFloat(numval)){
alert(numval + ' is not a number');
testform.number.name.select();
testform.number.name.focus();
}
}
</script>
</head>
<body>
<form name="testform">
<input type="text" name="whole" onBlur="wholenum(this)">Enter a whole number
<br>
<input type="text" name="number" onBlur="numfield(this)">Enter any number (incl. decimals)
</html>
Bookmarks