slide 1 of 5
There are many different ways to create a calendar in HTML. Before starting out though, the user has to determine the exact purpose of the calendar itself.
The calendar itself can be as simple as an HTML table that is formatted to form a calendar, or it can be an embedded script within the HTML website. There are also a number of online tools which allow a user to set the options that they require, and generate the code accordingly.
slide 2 of 5
Using HTML Tables
This method is perhaps the simplest but the most tedious one to create a calendar in HTML. The calendar is completely static and is hardcoded, which means the user has to manually generate months or years correctly.
An example of an HTML calendar, for the month of April 2010, using tables:
<title>HTML Calendar using Tables</title>
<table align="center" border=1 cellpadding=2>
<td>18<td>19<td>20<td>21 <td>22<td>23 <td>24
slide 3 of 5
A Calendar in ASP and VBScript
ASP (Active Server Pages) code is usually located on a web server, and sent to the web page, after being parsed into HTML. This enables the code to be dynamic without straining the client’s computer too much, and avoiding hassles when scripting is turned off on browsers.
The following code snippet populates the first row of the calendar, taking into consideration that the starting day of the week is Saturday:
The conditional construct is checking to see whether the date actually falls on that particular day of the week. The For loop allows the construct to keep executing, till the right day and date combination is found.
slide 4 of 5
The function receives two parameters for establishing the number of days in the month: the first is the month in question and the second is the year. The first conditional if statement sets the number of days to 30 in the case of April, June, September, and November. The second half set the variable to 31, and then checks if it is February. If the condition is true, a series of steps to check for leap years starts.
The programming condition for a leap year is that it must be divisible by 4. However, if the year is divisible by 4 or 100 but not by both, the year is not a leap year. For example, the year 1900 is not a leap year, in spite of being divisible by 4.
slide 5 of 5
Free Calendar Generators
There are a number of websites that put up free calendar generators, which let the user pick colors and set other parameters for their calendars. These pieces of code are usually free of charge, and require a backlink or a credit at the most. On the flip side, these snippets of code must be treated with the same caution reserved for most Internet transactions as well.