rewritten to fit javascript standards
This commit is contained in:
43
functions.js
43
functions.js
@@ -2,25 +2,44 @@
|
|||||||
|
|
||||||
var isFormElementInRange;
|
var isFormElementInRange;
|
||||||
|
|
||||||
function checkFormElementInRange (form, name, min, max ) {
|
/**
|
||||||
|
* Ensures a value submitted in a form is numeric and is in a range
|
||||||
|
*
|
||||||
|
* @param object the form
|
||||||
|
* @param string the name of the form field to check
|
||||||
|
* @param integer the minimum authorized value + 1
|
||||||
|
* @param integer the maximum authorized value + 1
|
||||||
|
*
|
||||||
|
* @return boolean whether a valid number has been submitted or not
|
||||||
|
*/
|
||||||
|
function checkFormElementInRange(theForm, theFieldName, min, max )
|
||||||
|
{
|
||||||
|
isFormElementInRange = true;
|
||||||
|
var theField = theForm.elements[theFieldName];
|
||||||
|
var val = parseInt(theField.value);
|
||||||
|
|
||||||
isFormElementInRange = true;
|
// It's not a number
|
||||||
var val = parseInt( eval( "form." + name + ".value" ));
|
if (isNaN(val)) {
|
||||||
|
alert('This is not a number!');
|
||||||
if(isNaN(val)) {
|
|
||||||
isFormElementInRange = false;
|
isFormElementInRange = false;
|
||||||
|
theField.select();
|
||||||
|
theField.focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (val < min || val > max ) {
|
// It's a number but it is not between min and max
|
||||||
alert( val +" is not a valid row number!" );
|
else if (val < min || val > max) {
|
||||||
|
alert(val + ' is not a valid row number!');
|
||||||
isFormElementInRange = false;
|
isFormElementInRange = false;
|
||||||
eval( "form."+ name + ".focus()");
|
theField.select();
|
||||||
eval( "form."+ name + ".select()");
|
theField.focus();
|
||||||
}else {
|
return false;
|
||||||
eval( "form."+ name + ".value = val" );
|
}
|
||||||
|
// It's a valid number
|
||||||
|
else {
|
||||||
|
theField.value = val;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
} // end of the 'checkFormElementInRange()' function
|
||||||
|
|
||||||
//-->
|
//-->
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user