Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

Calendar - year


< html >
< head >
< script >
function day_title(day_name) {
document.write( "<TD ALIGN=center WIDTH=35>" + day_name + "</TD>" )
}
function hilite_today(day,mm) {
if ((this_day == day) && (this_month == mm))
document.write( "<FONT COLOR=\"#FF0000\">" )
}
function makeArray(n) {
this .length = n;
for ( var i = 1; i <= n; i ++ )
this [i] = 0
return this
}
function fill_table(m_name,m_length,mm) {
day = 1
document.write( "<center><TABLE BORDER=3 CELLSPACING=3 CELLPADDING=%3><TR>" )
document.write( "<TD COLSPAN=7 ALIGN=center><B>" + m_name + "   " + this_year + "</B><TR>" )
day_title( "Sun" )
day_title( "Mon" )
day_title( "Tue" )
day_title( "Wed" )
day_title( "Thu" )
day_title( "Fri" )
day_title( "Sat" )
document.write( "</TR><TR>" )
for ( var i = 1;i < start_day;i ++ ) {
document.write( "<TD>" )
}
for ( var i = start_day;i < 8;i ++ ) {
document.write( "<TD ALIGN=center>" )
hilite_today(day,mm)
document.write(day + "</TD><FONT COLOR='#000000'>" )
day ++ ;
}
document.write( "<TR>" )
while (day <= m_length) {
for ( var i = 1;i <= 7 && day <= m_length;i ++ ) {
document.write( "<TD ALIGN=center>" )
hilite_today(day,mm)
document.write(day + "</TD><FONT COLOR='#000000'>" )
day ++
}
document.write( "</TR><TR>" )
}
document.write( "</TR></TABLE></center><BR>" )
start_day = i
}
</ script >
</ head >

< body Background = .. / graphics / grayback.jpg >
< center >< BR >< BR >< BR >
< script >
month = new makeArray(12)
month[1] = "January"
month[2] = "February"
month[3] = "March"
month[4] = "April"
month[5] = "May"
month[6] = "June"
month[7] = "July"
month[8] = "August"
month[9] = "September"
month[10] = "October"
month[11] = "November"
month[12] = "December"
month_length = new makeArray(12)
month_length[1] = 31
month_length[2] = 28
month_length[3] = 31
month_length[4] = 30
month_length[5] = 31
month_length[6] = 30
month_length[7] = 31
month_length[8] = 31
month_length[9] = 30
month_length[10] = 31
month_length[11] = 30
month_length[12] = 31
today = new Date ()
this_day = today.getDate()
this_month = today.getMonth() + 1
this_year = today.getYear();
if (this_year < 2000)     // Y2K Fix, Isaac Powell
this_year = this_year + 1900; // http://onyx.idbsu.edu/~ipowell
month_length[2] = (((this_year % 4 == 0) && (this_year % 100 != 0)) || (this_year % 400 == 0)) ? 29 : 28;
begin_date = new Date ( "January 1, 19" + this_year)
start_day = begin_date.getDay() + 1
if (start_day == 1) {
 start_day = 8
}
for ( var m = 1;m <= 12;m ++ ) {
fill_table(month[m],month_length[m],m)
}
</ SCRIPT >
</ center >
</ BODY >
</ html >

//Thanks to David Pye for his JavaScript Vault contribution