Home arrow HTML arrow Page 2 - Constructing the Current Month of a Web Page Calendar
HTML

Constructing the Current Month of a Web Page Calendar


Welcome to the third part of an eight-part series on building a web page calendar. In this part, we take a close look at the showCurrentMonth() function of the calendar. It is composed of seven code segments; we'll cover the first four here. These help pull together various parts of the month for display, such as the current year.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 27, 2009
TABLE OF CONTENTS:
  1. · Constructing the Current Month of a Web Page Calendar
  2. · The Third Code Segment
  3. · Third Code Segment continued
  4. · The Fourth Code Segment

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Constructing the Current Month of a Web Page Calendar - The Third Code Segment
(Page 2 of 4 )

This is the third code segment:


//fill in the date numbers.

for (i=0;i<=5;i++)

{

for (j=startMonthDay;j<=6;j++)

{

if (validateDate(currentYear, currentMonth, monthDayNo))

{

//create the ID for table cell of the start date

tdID = "M" + i + j;

document.getElementById(tdID).innerHTML = monthDayNo;

if (monthDayNo == monthDayNoToday)

IDToday = tdID;

//increment the monthDayNo

monthDayNo+=1;

}

}

//set the startMonthDay to 0 after first line

startMonthDay = 0;

}


The main purpose of this code segment is to fill the HTML table representing the calendar with the numbers for the days of the month. The TABLE element has six rows for the numbers. The number 1 is not necessarily placed in the first cell of the first row. The first cell is for Sunday, the second for Monday, third for Tuesday, etc. The number 1 does not fall on Sunday for every month. The corresponding day of the week has to be determined before the number is placed. Placing startMonthDay in the condition of the inner for-loop serves that purpose. This code segment also determines the ID for the table cell of the current day number of the month. We shall need to change its background color.

There are two for-loops here. The outer one is for the rows (six); the inner one is for the columns (seven). We count the rows from 0 to 5, giving six. We count the columns from 0 to 6, giving seven. The statements are inside the inner loop, except for one, which is outside the inner loop, but inside the outer loop.

The first statement is an if-statement. This if-test calls a function, validateDate(). This function is written by us; we shall see the details later. It receives as arguments the current year, the current month, and the number of the day of the month. If the combination of year, month and number for the day is correct, then the function returns true; otherwise, it returns false.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials