kommidi
02-05-2004, 01:23 AM
I have a function that validates the input onChange().In case of an error the function gives an alert message and keeps the focus on the same text box.I achieve this by the following snippet of code in the function using
if (alertbox!="") {alert(alertbox); entered.select(); entered.focus();
This worlks on Internet Explorer but does not on mozilla...
Please Help me on this....
Thanks
In case I am not clear I am attaching the code and the function call
Fuunction Call:
onChange="return numberValidation(this,1,10,'The Number Of Elements should be an Integer within the Range ','Integer'
Function
function numberValidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i")
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox); entered.select(); entered.focus();
} return false;}
else {return true;}
}
}
if (alertbox!="") {alert(alertbox); entered.select(); entered.focus();
This worlks on Internet Explorer but does not on mozilla...
Please Help me on this....
Thanks
In case I am not clear I am attaching the code and the function call
Fuunction Call:
onChange="return numberValidation(this,1,10,'The Number Of Elements should be an Integer within the Range ','Integer'
Function
function numberValidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i")
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox); entered.select(); entered.focus();
} return false;}
else {return true;}
}
}