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