<html>
<head>
<script language="javascript" type="text/javascript">
// For English users: getSign()
Date.prototype.getSign=function(){var zodiaque=new Array("aries","taurus","gemini","cancer","leo","virgo","libra","scorpio","sagittarius","capricorn","aquarius","pisces"),d,w,m;d=(367*this.getFullYear()-Math.floor((7*(this.getFullYear()+Math.floor((this.getMonth()+1+9)/12)))/4)+Math.floor((275*(this.getMonth()+1))/9)+this.getDate()-730530);w=(282.9404+4.70935E-5*d)-Math.floor((282.9404+4.70935E-5*d)/360.0)*360.0;m=(356.0470+0.9856002585*d)-Math.floor((356.0470+0.9856002585*d)/360.0)*360.0;return zodiaque[Math.floor(((w+m)-Math.floor((w+m)/360.0)*360.0)/30.0)];};
</script>
<script language="javascript" type="text/javascript">
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Test the validity of a French date (JJ/MM/AAAA).
// Return "OK" or an error message
// You can interchange the lines 19 and 20 (with indices correction) for a format such as MM/DD/AAAA
function isValidDate(date) {
var date, tab, reg = new RegExp("^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$","g");
if(reg.test(date)) {
tab=date.split('/');
if((tab[0]*1)<1 || (tab[0]*1)>31) { return "Incorrect day"; } // 19
if((tab[1]*1)<1 || (tab[1]*1)>12) { return "Incorrect month"; } // 20
return "OK";
}
return "Incorrect format date";
}
function sign() {
var thedate, date, tab;
date=document.test.date.value;
tab=date.split('/');
j=tab[0]*1; m=tab[1]-1; a=tab[2]*1;
thedate = new Date(a, m, j);
signe = thedate.getSign();
alert('People who are born on '+date+' are '+thedate.getSign());
}
// =========================================================================================
function verif() {
var thedate;
// get the values of the form
thedate = document.test.date.value;
if(!thedate) {
alert('Date is missing');
document.test.date.focus();
return false;
}
msg = isValidDate(thedate);
if(msg != "OK") {
alert("Date :\n"+msg);
document.test.date.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<h3>Signe du zodiaque</h3>
<form name="test" method="post" action="javascript:sign()" onsubmit="return verif()">
Write a date (DD/MM/AAAA) <input type="text" name="date" size="10"><input type="submit" name="submit" value="Validate">
</form>
</body>
</html>
|