PDA

View Full Version : Validate a specific date range



deziner76hd
05-06-2012, 12:02 AM
Hello,
I would like to have a specific date range in years entered into a text box and if anything else is entered a pop up alert would appear. The date range would be from 1912 to 2002. Any help with this would be greatly appreciated.

This is the Javascript I am trying to use:


<script type="text/javascript">
function checkDate(theForm)
year=document.getElementById('YearBorn').value;
if(year<1912 || year>2002)
{
alert("registration is restricted to those born between 1912 to 2002");
return false;
else {
return true;
}
}
</script>


I have included this code in the Additional Attributes:


onblur="return checkDate(this);"

keyboard
05-06-2012, 12:20 AM
So what's the problem that you're experiencing with this code?

deziner76hd
05-06-2012, 01:00 AM
First Thank you for asking.
The code does not validate and put up an alert if the a date out of range is entered.
The form is located here http://www.rocpinions.com/main-form.html and the question is at the top of page 2 of the multi form

Thanks
DeZiner

keyboard
05-06-2012, 01:07 AM
Try this instead -
<script type="text/javascript">
function checkDate(theForm) {
year=document.getElementById('YearBorn').value;
if(year<1912 || year>2002)
{
alert("registration is restricted to those born between 1912 to 2002");
return false;
else {
return true;
}
}
Also you're passing a paramater (theForm) but not using it.
</script>

deziner76hd
05-06-2012, 01:24 PM
ok I still can't get this working I am not a coder so this is giving me grief. How do I call this function? I am using

onblur="return checkDate(this);"

is that correct?

keyboard
05-07-2012, 12:54 AM
yep, just remove the old checkDate() function from your page and put in the new one. The only difference is you're missing a paranthesis {