kathyc
01-18-2009, 04:55 PM
Hello
On my webpage I have an input box named "quantity".
If the user enters nothing or a non-numeric value, an error box is displayed
and the user is not forwarded to another web page.
My code is partly working. It checks for the above conditions and displays the proper error message, but still wants to re-direct the page even if the value of the quantity field is not correct.
Below is my code. Can anyone let me now what I've done wrong?
function CheckQuantity(inp)
{
var sValidChars = "0123456789";
var sChar = "";
var iCount = 0;
var bIsValid = true;
var sTempValue = inp.value;
if (sTempValue.length == 0)
{
alert ("Please enter a valid quantity.");
bIsValid = false;
return bIsValid;
}
if (sTempValue.length > 0)
{
for (iCount=0; iCount < sTempValue.length && bIsValid == true; iCount++)
{
sChar = sTempValue.charAt(iCount);
if (sValidChars.indexOf(sChar) == -1)
{
alert ("Please enter a numeric value for quantity.");
bIsValid = false;
return bIsValid;
}
}
}
}
On my webpage I have an input box named "quantity".
If the user enters nothing or a non-numeric value, an error box is displayed
and the user is not forwarded to another web page.
My code is partly working. It checks for the above conditions and displays the proper error message, but still wants to re-direct the page even if the value of the quantity field is not correct.
Below is my code. Can anyone let me now what I've done wrong?
function CheckQuantity(inp)
{
var sValidChars = "0123456789";
var sChar = "";
var iCount = 0;
var bIsValid = true;
var sTempValue = inp.value;
if (sTempValue.length == 0)
{
alert ("Please enter a valid quantity.");
bIsValid = false;
return bIsValid;
}
if (sTempValue.length > 0)
{
for (iCount=0; iCount < sTempValue.length && bIsValid == true; iCount++)
{
sChar = sTempValue.charAt(iCount);
if (sValidChars.indexOf(sChar) == -1)
{
alert ("Please enter a numeric value for quantity.");
bIsValid = false;
return bIsValid;
}
}
}
}