-
data difference
I need to find the difference between a date entered in a form "txtDate" and the current date.
If the person is less than 21 I need to pop up a message rejecting them and then redirecting them to a new page.
Can anyone give me a bit of guidance on this. I am much more of a sever VBScript person.
TIA
-
I can't say if this is the best way or not, but I've done it this was before:
Code:
<script langauge="JavaScript">
function CalAge(bDay){
now = new Date()
born = new Date(bDay.value);
years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
return years;
}
function ReDir(iAge, sUrlUnderAge, sUrlOfAge){
if(iAge < 21){
alert("You must be 21 to enter this page. No redirecting you to: " + sUrlUnderAge);
location.href=sUrlUnderAge
} else {
alert("Welcome, enjoy your stay!")
location.href=sUrlOfAge
}
}
</script>
<form>
<input type="text" name="DofB" maxlength="10" size="12" onBlur="ReDir(CalAge(this), 'http://www.yahoo.com', 'http://www.realisticgraphics.com')">
</form>
Replace the URL parameters to the pages you want to redirect to. The first one is the site for under age users, the second is for of age users. This is by no means fool proof, obviously somebody could enter a fake date to get in, but it should answer your question though.