...

View Full Version : Help with Birthday script



coalfire
06-02-2005, 12:08 AM
Hi very new to this but have written a script that will check the date against an array and if it matches an entry will post a happy birthday message, but am having problems with the year part. Users havn't given me the year of birth only day and month but I can't get it to work without putting the year either 2005 or 2006 if birthday has already happened.

What do I need to take out or change in order for it to ignore any year (or prefrebly not need the year)

Here is the scrpit I have and thanks in advance for your help

<SCRIPT language="JavaScript" type="text/javascript">



<!-- Begin
var days = new Array();
var msgs = new Array();



days[1] = "June 1, 2005";
msgs[1] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Ben (test)!";



days[2] = "December 22, 2005";
msgs[2] = "<BR>Another day closer, almost there!";

days[3] = "December 23, 2005";
msgs[3] = "<BR>Tomorrow is Christmas Eve!";

days[4] = "December 24, 2005";
msgs[4] = "<BR>Today is Christmas Eve, thanks for visiting!";

days[5] = "December 24, 2005";
msgs[5] = "<BR>Welcome to this page on Christmas Day!";

days[6] = "January 01, 2006";
msgs[6] = "<BR>Happy New Year!";

days[7] = "March 02, 2006";
msgs[7] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Mazza";

days[8] = "September 12, 2005";
msgs[8] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>KinkyKate";

days[9] = "November 22, 2005";
msgs[9] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Jess";

days[10] = "April 01, 2006";
msgs[10] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Treemoose";

days[11] = "April 29, 2006";
msgs[11] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Sarah";

days[12] = "May 23, 2006";
msgs[12] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Kitten";

days[13] = "April 13, 2006";
msgs[13] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Katy";

days[14] = "October 14, 2005";
msgs[14] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Catherine";

days[15] = "August 03, 2005";
msgs[15] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Jules";

days[16] = "July 28, 2005";
msgs[16] = "<BR><IMG src='http://www.atrf94.dsl.pipex.com/forumsmile/birthday.gif' width='90' height='40' alt='Birthday'><BR>Hanzy";


var months = new Array("",
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
);

var today = new Date(); // today
var mon = months[today.getMonth() + 1]; // month
var day = today.getDate(); // day
var year = y2k(today.getYear()); // year

function dateMsg() {
for (i = 0; i < days.length; i++) {
tempdate = new Date(days[i]);
tempmonth = months[tempdate.getMonth() + 1];
tempday = tempdate.getDate();
tempyear = y2k(tempdate.getYear());
if (mon == tempmonth && day == tempday)
return("Today is " + days[i] + ". " + msgs[i]); // returns day message
}
return("Today is " + mon + " " + day + ", " + year + "."); // returns default
}

// Y2K Fix Function
function y2k(year) {
if (year < 2000)
year = year + 1900;
return year;
}
// End -->
</SCRIPT>


<script>
document.write(dateMsg());
</script>

Basscyst
06-02-2005, 12:16 AM
I wrote this for another poster a while back. Feel free to use it.



<html>
<head>
<script type="text/javascript">
function dateMessage()
{
var special_days=new Array();

\\******************************************************
\\ Add dates and messages here. Add as many as you like.
\\******************************************************

special_days[0]=new Array('Today is cool.','6/1/2005');
special_days[1]=new Array('It\'s one day after I got this script.','6/2/2005');
special_days[2]=new Array('Yay! Presents!','12/25/2005');
special_days[3]=new Array('Mmmm. Turkey.','11/25/2005');

\\******************************
\\ Don't edit below here
\\******************************

var now=new Date();
var m=now.getMonth()+1;
var d=now.getDate();
var y=now.getYear();
var dt=m+"/"+d+"/"+y;

for(var i=0;i<special_days.length;i++)
{
if(special_days[i][1]==dt)
{
var str=special_days[i][0];
}
}
document.getElementById('msg').innerHTML=str;
}
</script>
</head>
<body onload="dateMessage();">
<span id="msg"></span>
</body>
</html>


Basscyst

coalfire
06-02-2005, 12:22 AM
Cheers will have a look at that

coalfire
06-02-2005, 12:26 AM
Ok not getting any output, any ideas?

Basscyst
06-02-2005, 12:42 AM
Yes, I do have an idea. Why don't I lay off the crack, and put my comment tags the right way. :o



<html>
<head>
<script type="text/javascript">
function dateMessage()
{
var special_days=new Array();

//******************************************************
// Add dates and messages here. Add as many as you like.
//******************************************************

special_days[0]=new Array('Today is cool.','6/1/2005');
special_days[1]=new Array('It\'s one day after I got this script.','6/2/2005');
special_days[2]=new Array('Yay! Presents!','12/25/2005');
special_days[3]=new Array('Mmmm. Turkey.','11/25/2005');

//******************************
// Don't edit below here
//******************************

var now=new Date();
var m=now.getMonth()+1;
var d=now.getDate();
var y=now.getYear();
var dt=m+"/"+d+"/"+y;

for(var i=0;i<special_days.length;i++)
{
if(special_days[i][1]==dt)
{
var str=special_days[i][0];
}
}
document.getElementById('msg').innerHTML=str;
}
</script>
</head>
<body onload="dateMessage();">
<span id="msg"></span>
</body>
</html>


Basscyst

coalfire
06-02-2005, 12:59 AM
That would do it lol

Will have a look in the morning now as that ones just giving undefined but its 1am and can't think straight.

Thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum