Calendar for Current Month


Here's a calendar I fully intended to use on a client's site, but didn't. It's still a nice script and deserves to be used. It's also Y2K compliant, and bases the calendar shown on the visitor's date settings.

Our goal:

Stuff in blue can be changed to the colors of the page this script will be used on (the one below will have a white background). Month and day names may also be changed for non-English sites. Heck, you can probably use it for sci-fi/fantasy world based calendars too, keeping in mind that the dates will still be based on your visitor's computer's date settings. The script can go between the <BODY> and </BODY> tags.

<SCRIPT LANGUAGE="JavaScript">
<!--
/* This JavaScript was composed by Kristin J. Johnson.
*The Wererat's Lair: http://wererat.net */

// Array of month names
monthnames = new
Array("January","February","March","April","May","June","July","August","September","October","November","December");

function cal(month, day) {
var entry = new Array(3);
entry[0] = month;
entry[1] = day;

}
Array.calendar = cal;
mydays = new Array();
monthdays = new Array(12);
monthdays[0]=31;
monthdays[1]=28;
monthdays[2]=31;
monthdays[3]=30;
monthdays[4]=31;
monthdays[5]=30;
monthdays[6]=31;
monthdays[7]=31;
monthdays[8]=30;
monthdays[9]=31;
monthdays[10]=30;
monthdays[11]=31;

todayDate=new Date();
thisday=todayDate.getDay();
thismonth=todayDate.getMonth();
thisdate=todayDate.getDate();
thisyear=todayDate.getFullYear();

if (((thisyear % 4 == 0)
&& !(thisyear % 100 == 0))
||(thisyear % 400 == 0)) monthdays[1]++;
spaces=thisdate;
while (spaces > 7) spaces-=7;
spaces = thisday - spaces + 1;
if (spaces < 0) spaces+=7;
document.write("<TABLE BORDER=2 BGCOLOR='#FFFFFF' BORDERCOLOR='#000000'> ");
document.write("<TR><TD COLSPAN=7><CENTER><B>" + monthnames[thismonth] + " " + thisyear + "</B></CENTER></TD></TR>");
document.write("<TR>");
document.write("<TD ALIGN=center>Su</TD>");
document.write("<TD ALIGN=center>M</TD>");
document.write("<TD ALIGN=center>Tu</TD>");
document.write("<TD ALIGN=center>W</TD>");
document.write("<TD ALIGN=center>Th</TD>");
document.write("<TD ALIGN=center>F</TD>");
document.write("<TD ALIGN=center>Sa</TD>");
document.write("</TR>");
document.write("<TR>");

for (s=0;s<spaces;s++) {
document.write("<TD> </TD>");
}
count=1;
while (count <= monthdays[thismonth]) {
for (b = spaces;b<7;b++) {

document.write("<TD ALIGN=right>");
for (c=0;c<mydays.length;c++) {
if (mydays[c] != null) {

}
}
if (count==thisdate) {
document.write("<FONT COLOR='#FF0000'><B>");
}
if (count <= monthdays[thismonth]) {
document.write(count);
}
else {
document.write(" ");
}
if (count==thisdate) {
document.write("</B></FONT>");
}

document.write("</TD>");
count++;
}
document.write("</TR>");
spaces=0;
}
document.write("</TABLE>");
//-->
</SCRIPT>


Grab a text file of this JavaScript (right-click and save it as a text file).