KBSJohn
10-21-2003, 03:50 PM
I have a form that I want to accept and validate a date on, then use that date to compose a message to to user. Everything works as I would expect, unless you enter a date between 08/01/1985 and 09/30/1985. If you enter a date such as 9/30/1985, it will evaluate correct..... Don't have a clue, very new to this all, just trying to get a leg up.
Here's the script
<script>
dtFormat = 'MM/DD/CCYY'
function chkDt()
{
udt = document.frm.mdt.value;
if(udt.indexOf("/") == -1){
alert('Not a valid date, format '+dtFormat);
document.frm.mdt.focus();
return false;
}
dt1 = udt.split("/")
mm1 = parseInt(dt1[0]);
dd1 = parseInt(dt1[1]);
yy1 = parseInt(dt1[2]);
if(isNaN(dd1) || isNaN(mm1) || isNaN(yy1)){
alert('Invalid Date !');
return false;
}
dt2 = new Date(mm1+'/'+dd1+'/'+yy1)
dd2 = dt2.getDate();
mm2 = dt2.getMonth()+1;
yy2 = dt2.getFullYear();
//alert(dd1+'/'+mm1+'/'+yy1);
//alert(dd2+'/'+mm2+'/'+yy2);
if(dd1==dd2 && mm1==mm2 && yy1==yy2)
{
//alert('Year '+yy2)
//if (yy2=='1985') alert('Must Play 18U');
//else
if (mm2<09) yy2=yy2-1;
else yy2=yy2;
yy2=2003-yy2;
alert('Must Be Playing '+yy2+'U');
}
else
alert('Invalid Date ! ');
document.focus();
}
</script>
and how I use it
<center>
<form name=frm>
Enter a Birth Date (MM/DD/CCYY) <input type=text name=mdt size=8 maxlength=10>
<br>
<input type=button value="Check Date" onclick="chkDt()">
<br>
</form>
</center>
Here's the script
<script>
dtFormat = 'MM/DD/CCYY'
function chkDt()
{
udt = document.frm.mdt.value;
if(udt.indexOf("/") == -1){
alert('Not a valid date, format '+dtFormat);
document.frm.mdt.focus();
return false;
}
dt1 = udt.split("/")
mm1 = parseInt(dt1[0]);
dd1 = parseInt(dt1[1]);
yy1 = parseInt(dt1[2]);
if(isNaN(dd1) || isNaN(mm1) || isNaN(yy1)){
alert('Invalid Date !');
return false;
}
dt2 = new Date(mm1+'/'+dd1+'/'+yy1)
dd2 = dt2.getDate();
mm2 = dt2.getMonth()+1;
yy2 = dt2.getFullYear();
//alert(dd1+'/'+mm1+'/'+yy1);
//alert(dd2+'/'+mm2+'/'+yy2);
if(dd1==dd2 && mm1==mm2 && yy1==yy2)
{
//alert('Year '+yy2)
//if (yy2=='1985') alert('Must Play 18U');
//else
if (mm2<09) yy2=yy2-1;
else yy2=yy2;
yy2=2003-yy2;
alert('Must Be Playing '+yy2+'U');
}
else
alert('Invalid Date ! ');
document.focus();
}
</script>
and how I use it
<center>
<form name=frm>
Enter a Birth Date (MM/DD/CCYY) <input type=text name=mdt size=8 maxlength=10>
<br>
<input type=button value="Check Date" onclick="chkDt()">
<br>
</form>
</center>