HTML and CSS Reference
In-Depth Information
Figure 12-25
adding blank cells before the first day of the month
2. Save your changes to the file.
Writing the Calendar Days
Finally, you'll write the table cells for each day of the month using the following for loop:
var totalDays = daysInMonth(calendarDay);
for (var i = 1; i <= totalDays; i++) {
weekDay = day.getDay();
if (weekDay == 0) document.write(“<tr>”);
document.write(“<td class='calendar_dates'>” + i + “</td>”);
if (weekDay == 6) document.write(“</tr>”);
The code starts by determining the total days in the month using the daysInMonth()
function you created earlier. It then loops through those days, and each time through the
loop it changes the day and weekDay variables to match the current day being written. If
the day is a Sunday, a new table row is started; if the day is a Saturday, the current table
row is ended. Each table cell displays the day number and belongs to the calendar_dates
class, which allows it to be styled using the style rule from the calendar.css style sheet.
You'll add this code to the writeCalDays() function now.
Search WWH ::

Custom Search