Home arrow HTML arrow Page 2 - 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 - The validateDate() Function
(Page 2 of 5 )

If you set the year, month and number for the day of the month for a date object, JavaScript will not know if that combination is valid. For example, the date, 02/29/2007 does not exist. This says February 29, 2007. The year 2007 is not a leap year, so February 2007 end on the 28th and not the 29th. JavaScript cannot check this. We need to write a function that will check that.

A function to validate dates is not straightforward. Understanding it is a subject worthy of an entire article. Here I will simple tell you what enters the function and what goes out of it. You will need to consult some other document for the explanation of the function that I will give you.

The function here receives as arguments the year, the month and the number of the day of the month. It verifies whether the combination is possible. If the combination is possible, it returns true; if it is not, it returns false.

This is the function:


{

var noMonthDays = new Array(12);

noMonthDays[0] = 31;

noMonthDays[1];

noMonthDays[2] = 31;

noMonthDays[3] = 30;

noMonthDays[4] = 31;

noMonthDays[5] = 30;

noMonthDays[6] = 31;

noMonthDays[7] = 31;

noMonthDays[8] = 30;

noMonthDays[9] = 31;

noMonthDays[10] = 30;

noMonthDays[11] = 31;

 

if ((year%4)!=0)

noMonthDays[1] = 28;

else if ((year%400)==0)

noMonthDays[1] = 29;

else if ((year%100)==0)

noMonthDays[1] = 28;

else

noMonthDays[1] = 29;

 

if ((year.length = 4)&&(no<=noMonthDays[month])&&(no>=1))

return true;

else

return false;

}




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