Forum Moderators: open
any ideas? I did some searches but havnt really found anything usefull.
<script language="javascript">
function checkAge()
{
/* the minumum age you want to allow in */
var min_age = 18;
/* change "age_form" to whatever your form has for a name="..." */
var year = parseInt(document.forms["age_form"]["year"].value);
var month = parseInt(document.forms["age_form"]["month"].value) - 1;
var day = parseInt(document.forms["age_form"]["day"].value);
var theirDate = new Date((year + min_age), month, day);
var today = new Date;
if ( (today.getTime() - theirDate.getTime()) < 0) {
alert("You are too young to enter this site!");
return false;
}
else {
/* set the age check cookie here so it can be found on all pages (if they have cookies enabled!) */
return true;
}
}
</script>
///
then the form looks like this:
///
<form action="http://www.example.com" method="post" name="age_form">
Day : <select name="day">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
... values removed here ...
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
Month : <select name="month">
<option>1</option>
<option>2</option>
<option>3</option>
... values removed here ...
<option>10</option>
<option>11</option>
<option>12</option>
</select>
Year : <select name="year">
<option>2003</option>
<option>2002</option>
<option>2001</option>
... values removed here ...
<option>1905</option>
<option>1904</option>
<option>1903</option>
</select>
<input type="submit" name="senddate" value="Go" onClick="return checkAge()">
///
this doesn't stop users telling fibs though!
///