XtrmelyCanadian
04-25-2003, 01:32 AM
I am doing some javascript validation for a project and i get an error when trying submit the right values, i get the debug window popping up. I am checking to see if an entered field is a valid price, it does catch the error if i try to submit a invalid price, but when its a valid price a debug window pops up. ANY SUGGESTIONS as to what it could be.
<script language="javascript">
<!--
function Validate(TheForm)
{
if (TheForm.Price.value == "")
{
alert("Please enter a price");
document.TheForm.Price.focus();
return false
}
if (TheForm.YearCur.value == "")
{
alert("Please enter a year");
document.TheForm.YearCur.focus();
return false
}
var Year=document.TheForm.YearCur;
var Price=document.TheForm.Price;
if (isInteger(Year.value)==false)
{
alert("Please enter a valid year eg. 1981");
Year.value="";
Year.focus();
return false;
}
if (isIntegerPrice(Price.value)==false)
{
alert("Please enter a valid year eg. 1981");
Price.value="";
Price.focus();
return false;
}
}
function isIntegerPrice(p)
{
var a;
for (a = 0; a < p.length; a++)
{
var e = p.charAt(i);
if (((e < "0") || (e > "9") || (!e.equals(".")))
{
return false;
}
}
return true;
}
function isInteger(s)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (((c < "0") || (c > "9")))
{
return false;
}
}
return true;
}
//-->
</script>
My button calls the validate function, im also checking for a year as well. I bolded the text of the line that seems to be giving me the error.
<script language="javascript">
<!--
function Validate(TheForm)
{
if (TheForm.Price.value == "")
{
alert("Please enter a price");
document.TheForm.Price.focus();
return false
}
if (TheForm.YearCur.value == "")
{
alert("Please enter a year");
document.TheForm.YearCur.focus();
return false
}
var Year=document.TheForm.YearCur;
var Price=document.TheForm.Price;
if (isInteger(Year.value)==false)
{
alert("Please enter a valid year eg. 1981");
Year.value="";
Year.focus();
return false;
}
if (isIntegerPrice(Price.value)==false)
{
alert("Please enter a valid year eg. 1981");
Price.value="";
Price.focus();
return false;
}
}
function isIntegerPrice(p)
{
var a;
for (a = 0; a < p.length; a++)
{
var e = p.charAt(i);
if (((e < "0") || (e > "9") || (!e.equals(".")))
{
return false;
}
}
return true;
}
function isInteger(s)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (((c < "0") || (c > "9")))
{
return false;
}
}
return true;
}
//-->
</script>
My button calls the validate function, im also checking for a year as well. I bolded the text of the line that seems to be giving me the error.