Welcome to the second part of an eight-part series on building a web page calendar. In this part of the series, I will explain the function that is used to create the current calendar. When the Show Current Month's Calendar button is clicked, it should call a function that will display the calendar of the current month. We need to modify it; the showCal() function we saw in the previous part has only one line. We will change this function and use it as the showCurrentMonth() function.
Change the name of the showCal() function to showCurrentMonth(). Erase its one line content. We shall give it new content. Replace the HTML code for the calendar with the following, which now has IDs and no cell contents:
The cells in the second row (not the first) have been given IDs, namely M00 and M01 through M06. Those in the third row have been given the IDs M10, M11, and so forth. The IDs have been given in this way, until in the seventh row, the IDs are M50 and M51 through M56.
Note that there are seven rows in the table and not six. The first row is taken up by the abbreviations of the days of the week. I have not given them IDs. Their contents do not need to be changed. Note the IDs and attributes I have given to the Input Text elements. The first one will have the name of the month and the second one will have the year.
Now, we have changed the name of the function that is called by the "Show Current Month Calendar" button. We have to modify the attribute of the button accordingly. The button tag should now be:
<button type="button" onclick="CalJustClicked = true; showCurrentMonth()">Show Current Month's Calendar</button>
Before we leave this section, note that the table cells currently hold no content; that is, they are all blank.