File: example.html

Recommend this page to a friend!
  Classes of Pierre FAUQUE  >  JavaScript Zodiac Sign  >  example.html  >  Download  
File: example.html
Role: Example script
Content type: text/plain
Description: Example of use
Class: JavaScript Zodiac Sign
Get the Zodiac sign for a given date
Author: By
Last change:
Date: 7 years ago
Size: 2,418 bytes


Class file image Download
<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 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)) {
		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;;
	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 =;

	if(!thedate) {
		alert('Date is missing');;
		return false;

	msg = isValidDate(thedate);
	if(msg != "OK") {
		alert("Date :\n"+msg);;
		return false;

	return true;


<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">