HTML Components: The ANYDAY and TODAY HTCs | WebReference

HTML Components: The ANYDAY and TODAY HTCs

HTML Components


The ANYDAY Component is defined in This component is an encapsulation of the calendar cells. The component name is determined by the XML namespace definition on the first line:


As oppose to, you have only one namespace definition. The reason is that we don't call any HTCs from this page. This is a "leaf" HTC. The custom tag we define here is DAY. We define its behavior as well now. HTML Component definition is actually a custom tag's behavior definition. The behavior includes one property and one event:

  <ATTACH EVENT="oncontentready" ONEVENT="fnInit()"<>/ATTACH>

Notice the event oncontentready. It occurs when the file completes its loading when imported by its caller, The event handler is fnInit(). Let's look at it:

function fnInit() {
  document.body.innerHTML = element.value;
  document.body.className = "clsDay";
  defaults.viewLink = document;
  element.appointments = ""; = element.value;

The fnInit() demonstrates some very important HTC's concepts. The first line assign element.value to the innerHTML property of the cell. An HTML Component is always encapsulated in an object named element. The property value is defined above in the PROPERTY tag. As a reminder, the actual value is passed in the caller,

text += '<TD><ANYDAY:DAY value=' + dayOfMonth + '></ANYDAY:DAY></TD>'

The style of the cell is assigned on the second line:

document.body.className = "clsDay";

Style class clsDay is defined elsewhere on the page:

  .clsDay {

Notice that days are colored light yellow in the calendar. It proves that the HTC dominates any format assignments made by the caller,

The third line of fnInit() sets the viewLink property of the defaults object. The viewLink property is the cornerstone of HTML Components. It allows an HTC's document ( to be viewed in another HTML document ( Here is the assignment of viewLink:

defaults.viewLink = document;

Notice that what you need to link is the whole document object. The last two lines of fnInit() initializes two internal properties that we'll explain later:

element.appointments = ""; = element.value;

Besides displaying itself, the DAY HTML Component reacts to mouse clicks:

<BODY onclick="fnShowAppts()">

When a day is clicked, the user is prompted to add his or her appointments for the day, or to modify the existing ones:

function fnShowAppts() {
  newAppointments = prompt("Add your appointment:",
  if (newAppointments != null) element.appointments = newAppointments;
  document.body.innerHTML = '<FONT COLOR="red">' + +
    '</FONT>'  + "<BR>" + '<FONT SIZE="1">' + element.appointments +

The input mechanism here is quite primitive. The user needs to put newline tags (<BR>) between appointments, or else they will all be in a single line. The final innerHTML is a concatenation between the day's date ( and the appointments (element.appointments).

The TODAY HTML Component ( is very similar to the ANYDAY Component ( The only difference is that background-color in the STYLE block is pink instead of ligthyellow, and the font color is blue instead of red. Observe in the calendar that the current day is colored pink with blue font.

Next: Listings of Calendar's top page

Produced by Yehuda Shiran and Tomer Shiran

Created: July 3, 2000
Revised: July 3, 2000