HTML and CSS Reference
In-Depth Information
Putting it all together, the JavaScript code to write the first row of the calendar table is:
document.write(“<tr>”);
document.write(“<th id='calendar_head' colspan='7'>”);
document.write(monthName[thisMonth] + “ “ + thisYear);
document.write(“</th>”);
document.write(“</tr>”);
You'll complete the writeCalTitle() function by adding the commands to create the
thisMonth and thisYear variables, and to write the HTML code for the first table row.
To complete the writeCalTitle() function:
1. Insert the following commands into the writeCalTitle() function, as shown in
Figure 12-8:
/* The thisMonth variable contains the calendar month number,
the thisYear variable contains the 4-digit year value */
var thisMonth = calendarDay.getMonth();
var thisYear = calendarDay.getFullYear();
// Write the table header row of the calendar table
document.write(“<tr>”);
document.write(“<th id='calendar_head' colspan='7'>”);
document.write(monthName[thisMonth] + “ “ + thisYear);
document.write(“</th>”);
document.write(“</tr>”);
Figure 12-8
writing the table header row
HTML code for the
table header row
2. Save your changes to the file.
Next, you must specify a date for the calendar to display. For now, you will add a
Date object named calDate to the calendar() function, storing the date July 6, 2015 . You
then will call the writeCalTitle() function using this date as the value for the calendarDay
parameter.
Search WWH ::




Custom Search