Building the Current Year with a Web Page Calendar
(Page 1 of 4 )
In the previous part of this eight-part series on building a web page calendar, we began a discussion of how to get the program to display any month the user wished to see. In this part, we complete that aspect of the application, and take the first step to enabling it to display an entire year. This is the fifth part of the series.
Show any Month’s Calendar
As we indicated in the previous part, the tag for the Show any Month’s Calendar is now
<button type="button" onclick="CalJustClicked = true; receiveYearMonth()">Show any Month’s Calendar</button>
The aim of this button is to enable you to display a month of your choice. To achieve this, you need to input the year, and the month of the year (January or February --- December).
When you click the button, it calls the “receiveYearMonth()” function. This function shows a prompt (dialog) box, which receives the year. After that it prompts you, by opening another dialog box, for the month.
This is the code for the function:
function receiveYearMonth()
{
var yearMonth = false;
var year = prompt("Please enter the year.","")
//check if the year is valid
if ((year >= 1900)&&(year.length == 4))
{
yearMonth = true;
}
else
{
alert('Year must be made up of 4 digits')
yearMonth = false;
}
if (yearMonth == true)
{
var month = prompt("Please enter the month in figures","")
//check if the month is valid
if ((month >= 1)&&(month <= 12))
{
yearMonth = true;
month--;
}
else
{
alert('Month must be between 1 and 12, inclusive')
yearMonth = false;
}
}
if (yearMonth == true)
{
var date = new Date(year, month,1);
showMonth(date, "");
}
}
Next: Explanation of the receiveYearMonth() Function >>
More HTML Articles
More By Chrysanthus Forcha