Home arrow HTML arrow Page 4 - Showing Any Month with a Web Page Calendar
HTML

Showing Any Month with a Web Page Calendar


Welcome to the fourth part of an eight-part series on constructing a web page calendar. In the previous part, we discussed the first four code segments for the ShowCurrentMonth function of this application. In this part, we will tackle the last three code segments, move on to the validateDate function, and make modifications that will let you accurately display any month of any year.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
May 04, 2009
TABLE OF CONTENTS:
  1. · Showing Any Month with a Web Page Calendar
  2. · The validateDate() Function
  3. · The Buttons
  4. · Need to modify the showCurrentMonth() Function
  5. · Modifying Statements in the showMonth() function

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Showing Any Month with a Web Page Calendar - Need to modify the showCurrentMonth() Function
(Page 4 of 5 )

We had finished with the showCurrentMonth() Function.

The showCurrentMonth() function has almost all that you need to display the calendar of any month. Should we write a separate function for Any Month’s Calendar? No; this will make the code too long. So, we shall modify the showCurrentMonth() function and any associated feature in the corresponding button’s tag.

Change the name showCurrentMonth() to showMonth(date, theMonth) at the start of the showCurrentMonth() function. The showCurrentMonth() function did not have any parameters. The new showMonth(date, theMonth), which will be the modification of the showCurrentMonth() function, needs two parameters, which are the date and theMonth. The date parameter is for the date object. The theMonth parameter is to indicate whether we are dealing with the current month or any month.

Add the following attributes to the button with the Show any Month’s Calendar title.


onclick="CalJustClicked = true; receiveYearMonth()"


The “CalJustClicked = true” portion has the same function as for the Show Current Month's Calendar button. The “receiveYearMonth()” portion calls an entirely new function whose name is, of course, receiveYearMonth(). The aim of the function is to get the year and month from the user for the particular month whose calendar he wants.

This function will issue two prompt dialog boxes. The first one will ask the user for the year whose month he is looking for, and the next one will ask the user for the month (January, February, --- December). This function, receiveYearMonth(), calls the showMonth(date, theMonth) function, which produces the calendar of the month of the user’s choice. The calendar of your (the user’s) choice is what we have been referring to as Any Month’s Calendar.

Now the onclick attribute of the first button, Show Current Month's Calendar, has to be modified, from


onclick="CalJustClicked = true; showCurrentMonth()"


to


<button type="button" onclick="CalJustClicked = true; showMonth(new Date(),'current')"


We replace the “showCurrentMonth()” portion of the onclick attribute with “showMonth(new Date(),'current')”. Note that our “showMonth(new Date(),'current')” here, calls the showMonth(date, theMonth) function.

The date argument in our attribute is “new Date().” This expression creates the current date object. The resulting current date object is sent as an argument.

The second argument is the word “current.” The showMonth(date, theMonth) function will use this to decide whether or not to create the calendar of the current month.


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 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials