JavaScript Calendar Display v1.1.0

A custom JavaScript object to display monthly or yearly calendars.

Public Domain

CalendarDisplay v1.1.0 (found in the CalendarDisplay110.js file) and in the Or View the Code section, plus examples and prior released versions, are released to the public domain. See Terms & Conditions for details. The content on this page is still copyrighted.

Overview

Try It <> Download Section <> Or View Code <> Try It Code <> Constructor <> Methods <> Release Notes

Try It

Month Day (1-31) Year (e.g. 2002)
Month Year

Download It

CalendarDisplay110.js

The CalendarDisplay JavaScript object and its methods are in this JS file. Download it, and put it in the same directory as any html pages that will use it. Put the following tag in those html files:

<script language="JavaScript" src="CalendarDisplay110.js"></script>

If the above link for CalendarDisplay110.js is not working, you may want to try the "Save ... As" option available in most browsers. For example, in Windows IE5, right click on the link and select Save Target As... If you have any questions, you can use our Feedback form.

Or View the Code in CalendarDisplay110.js

Display in new window (better for viewing)
Select All (better for copying)

View full HTML/JavaScript for the Try It example.

Display in new window (better for viewing)
Select All (better for copying)

Constructor

CalendarDisplay()

To use the CalendarDisplay methods, you must create an instance of the CalendarDisplay object using its constructor. There are no arguments for the constructor.

Constructor - Example

var calendar = new CalendarDisplay();

Methods

setDayFormat(dayF)
  - Sets the formatting for the days at the top of a calendar month. By default, it is a one letter format.
dayF - Should use one of the following constants, which are referenced from an instance of CalendarDisplay. The corresponding day format follows each constant:
ONE_LETTER S M T W T F S
TWO_LETTER Su Mo Tu We Th Fr Sa
THREE_LETTER SUN MON TUE WED THU FRI SAT
FULL_LETTER Sunday Monday Tuesday Wednesday Thursday Friday Saturday
 
createMonth(cdMonth, cdDay, cdYear)
  - Returns the HTML output for one month.
cdMonth - The value for the month, which can be a number from 0 to 11, where 0 is January. If the number is out of range, a message will indicate the month is invalid.
cdDay - The value for the day, which can be a number from 1 to 31, or whatever the limit is for the given month. A number within the month's range will display as highlighted in the calendar. The calendar will display without a highlighted day when the number is out of range.
cdYear - The value for the year, which should be the full year, such as 2000.
 
createYear(cdMonth, cdDay, cdYear)
  - Returns the HTML output for every month in a year.
cdMonth - The value for the month, which can be a number from 0 to 11, where 0 is January. An in-range value is only necessary for a highlighted day.
cdDay - The value for the day, which can be a number from 1 to 31, or whatever the limit is for the given month. An in-range value is only necessary for a highlighted day.
cdYear - The value for the year, which should be the full year, such as 2000.
 

Methods - new in version 1.1.0

Refer to the comments in CalendarDisplay110.js for details, and the code in the Try It example for usage.

setLinkOn(handlerName)
setLinkOff()
setNavigationOn(objectName)
setNavigationOff()
setOpenOn()
setOpenOff()
setAutoCloseOn()
setAutoCloseOff()

Methods - example

var nowDate = new Date();
var calendar = new CalendarDisplay();
calendar.setDayFormat(calendar.TWO_LETTER);
document.writeln(calendar.createMonth(nowDate.getMonth(), nowDate.getDate(), nowDate.getFullYear()));

The above example uses the Date object, which is a JavaScript Core object.
Read more at http://developer.netscape.com/docs/manuals/js/client/jsref/date.htm
The result produced by the example is:

Release Notes

Calendar Display v1.1.0 - download: CalendarDisplay110.js
Released 14-November-2002
Added new features to CalendarDisplay, including opening a window, linking the days, navigating months/years, and closing the window when selecting a link. Tested basic functionality against Internet Explorer 5.0 and Netscape 4.74 and 6.1 on Windows 2000. All functioned properly.

Calendar Display v1.0.0 - download: CalendarDisplay.js
Released 08-June-2002
Original release. Tested against Internet Explorer 5.0 and Netscape 3.04, 4.74, and 6.1. The basic script works in all those browsers, but Netscape 3.04 has certain problems with the examples, like not supporting the Date.getFullYear() method.

About this page: