Forum Moderators: open

Message Too Old, No Replies

Age Checker Script

Age Checker

         

Gateway

6:14 am on Jun 15, 2006 (gmt 0)

10+ Year Member



Im looking for some SEO safe js that I can have a pull down of day/month/year for age check, that then lets the surfer go to the page if they are of a X age. Also each one of these protected pages should check to make sure they have entered their date.. prob some cookie check..

any ideas? I did some searches but havnt really found anything usefull.

proper_bo

7:18 am on Jun 15, 2006 (gmt 0)

10+ Year Member



////
stick this in the head of the page:
////

<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!
///