I am trying to write a script to make sure that the user enters specific values ( 0.5,1,3,5, or 10) or else get an alert box. I have a script for another field that validates on a range, but I can't seem to modify it to work for *specific* values. Below is the range script, which works fine for a range. The function is called onBlur of the field with parameters passed in the onBlur event.
function valuevalidation(entered, min, max, alertbox, datatype){
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
//This is the onBlur event:
/* <input name="P" type="text" onBlur="valuevalidation(this, 1, 5,'Value MUST be an Integer in the range: 1-5');" onChange="add();" size="2">
*/
function valuevalidation(entered, min, max, alertbox, datatype){
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
//This is the onBlur event:
/* <input name="P" type="text" onBlur="valuevalidation(this, 1, 5,'Value MUST be an Integer in the range: 1-5');" onChange="add();" size="2">
*/