Question
Javascript 99.9% there - Thanks to Lionstone
Hey Gang,
Thanks to Lionstone, I have my javascript function just about perfect.
There's one small item not working, so I thought I'd throw it out there.
The script first checks that a value is entered into a field, then check
that it is betwwen a number range.
At first, it didn't work. It would tell me to enter DOB regardless of what I
put in there.
Then I removed this line for testing:
ThisYear = ThisYear.replace(/[^/d]/g,"");
With that line removed, the script successfully checked for the instance of
an entered value, if something is entered it checked that the number value
is betwwen the number range.
It put up the proper alerts if either criteria wasn't met.
Thing is, I can put alpha characters in there, and it will be accepted.
I suspect that's because the line of code I took out converts the value
entered either into a date, or a number.
Any help checking that last item would be a great help.
Thanks
-Dave
var ThisYear = ThisForm_Right.DOB_Year.value;
ThisYear = ThisYear.replace(/[^/d]/g,"");
if(ThisYear.length == 0)
{
alert("Please enter the year of your DOB.");
ThisForm_Right.DOB_Year.focus();
return false;
}
else
{
ThisYear = parseInt(ThisYear);
if((ThisYear < 1900) || (ThisYear > 2006))
{
alert ("The year of your DOB must be between 1900 and 2006.");
ThisForm_Right.DOB_Year.focus();
return false;
}
}
Thanks to Lionstone, I have my javascript function just about perfect.
There's one small item not working, so I thought I'd throw it out there.
The script first checks that a value is entered into a field, then check
that it is betwwen a number range.
At first, it didn't work. It would tell me to enter DOB regardless of what I
put in there.
Then I removed this line for testing:
ThisYear = ThisYear.replace(/[^/d]/g,"");
With that line removed, the script successfully checked for the instance of
an entered value, if something is entered it checked that the number value
is betwwen the number range.
It put up the proper alerts if either criteria wasn't met.
Thing is, I can put alpha characters in there, and it will be accepted.
I suspect that's because the line of code I took out converts the value
entered either into a date, or a number.
Any help checking that last item would be a great help.
Thanks
-Dave
var ThisYear = ThisForm_Right.DOB_Year.value;
ThisYear = ThisYear.replace(/[^/d]/g,"");
if(ThisYear.length == 0)
{
alert("Please enter the year of your DOB.");
ThisForm_Right.DOB_Year.focus();
return false;
}
else
{
ThisYear = parseInt(ThisYear);
if((ThisYear < 1900) || (ThisYear > 2006))
{
alert ("The year of your DOB must be between 1900 and 2006.");
ThisForm_Right.DOB_Year.focus();
return false;
}
}