| |||||||||||
Data Entry ValidationChecking for a valid range of valuesThis example shows a sample validation routine that checks for a given range of numbers. The range to test is variable, and in this sample is from Now, let's explore the code. <script language="JavaScript">
<!--
function validateRange ( fld, lowval, hival ) {
if ( fld.value=='' ) {
alert ( 'Please enter a value' )
fld.select ( ); return false
}
else if ( ( fld.value < lowval ) || ( fld.value > hival ) ) {
var msg = ''
if ( fld.value < lowval ) { msg = 'LESS' }
else { msg = 'MORE' }
alert ( 'Sorry, the entry is ' + msg + ' than expected.' )
fld.select ( ); fld.focus ( ); return false
}
else alert ( 'Yes! Welcome to the Club.' )
return true
}
//-->
</script>
<form onsubmit="return validateRange ( age, 18, 45 )">
<input type="text" name="age" size="3" maxlength="3">
<input type="submit" value="Check">
</form>
See AlsoValidating Against a Range of Values ( Web Forms ) Web Forms Validation |
| ||||||||||
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme