Create a Simple Calendar using Javascript

Pin It


calen
When I started my first project as a Programmer, I was told to put a calendar at the sidebar of the webpage. At that time, one of my friend help me with the code. This time I googled it and found one very simple and good sample of creating a calendar using JavaScript. I hope this will be helpful to others too.

There are few simple steps for creating a calendar

Step 1:
Insert the following codes into the HEAD section of your webpage:

<style type="text/css">
 
.main {
width:200px;
border:1px solid black;
}
 
.month {
background-color:black;
font:bold 12px verdana;
color:white;
}
 
.daysofweek {
background-color:gray;
font:bold 12px verdana;
color:white;
}
 
.days {
font-size: 12px;
font-family:verdana;
color:black;
background-color: lightyellow;
padding: 2px;
}
 
.days #today{
font-weight: bold;
color: red;
}
 
</style>
 
 
<script type="text/javascript" src="basiccalendar.js"></script>

Step 2:
Download basiccalendar.js (by right clicking, and selecting “Save As”), and upload to your webpage directory.

Step 3:
Finally, insert the below script where you wish the calendar to appear on your page:

<script type="text/javascript">
 
var todaydate=new Date()
var curmonth=todaydate.getMonth()+1 //get current month (1-12)
var curyear=todaydate.getFullYear() //get current year
 
document.write(buildCal(curmonth ,curyear, "main", "month", "daysofweek", "days", 1));
</script>

Click here to see an DEMO

1 comment on this postSubmit yours
  1. doesn’t work on IE9 or Firefox

2 total pingbacks on this post
  1. Design Gala
Submit your comment

Please enter your name

Your name is required

Please enter a valid email address

An email address is required

Please enter your message

Twitter

  • May 2, 2012 04:15

    10 Free WordPress Theme To Make You Forget About Premium Theme http://t.co/YRiLCiVa

  • March 2, 2012 17:16

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/FY0jh8Dn

  • March 2, 2012 16:43

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/QUlYKInf #IE #FF #Chrome #Testing #CrossBrowser

  • March 2, 2012 12:52

    Top 5 Plugins to Build Contact Form for WordPress http://t.co/PWyR08Iq #WordPress #Plugins #ContactForm

  • June 11, 2011 02:49

    CSS 3 Transitions http://bit.ly/m0pK3t

Design Gala © 2012 All Rights Reserved

Designed by 76miles

Powered by WordPress

More in CSS (8 of 15 articles)
box2