javascript| Control | calendar
The Calendar control using JS writing, from the http://expo.live.comof MS, the site sorting, hope for everyone useful.
Two pictures required in this program:
Http://expo.live.com/http://www.webjx.com/htmldata/2006-04-04/Images/leftArrow.gif
Http://expo.live.com/http://www.webjx.com/htmldata/2006-04-04/Images/rightArrow.gif
Global.css
Td.negdate A
{
Color: #808080;
}
. calendar
{
padding-left:4px;
padding-right:4px;
}
. Calendar table
{
Border-bottom:solid 1px #366AB3;
Text-align:center;
padding:0;
}
. Calendar Table A
{
Color:black;
}
. calendar TD {
padding:4px;
font-size:8pt;
Font-weight:lighter;
}
. CALENDARHD
{
Color: #366AB3;
Text-transform:uppercase;
}
. calendardays
{
Border-bottom:solid 1px;
Color: #808080;
padding:0;
margin:0;
}
. selectedDate {
Background:orange;
}
. selectedDate a {
Color:white!important;
}
Global.js
var calendar_daynames = new Array ("Day", "one", "two", "three", "four", "five", "six");
var calendar_monthnames = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function Showcalendar (Targetid, TargetUrl, Dmonth, Dyear, DDay)
{
if (Dmonth < 0)
{
Dmonth = 11;
dyear--;
}
if (Dmonth > 11)
{
Dmonth = 0;
dyear++;
}
var dnow = new Date ();
if (DDay = && Dmonth = = Dnow.getmonth () && dyear = = Dnow.getyear ()) DDay = Dnow.getdate ();
var dcurfd = new Date (Dyear, Dmonth, 1);
var dgivendate = new Date (dyear, Dmonth, DDay);
var dcurrentmonthfirstsunday = Dcurfd.getday ();
var dcurrentviewdate = new Date (DCURFD);
var idays = 0;
var weekmilliseconds = 1000*60*60*24*7;
if (Dcurrentmonthfirstsunday > 0) idays =-dcurrentmonthfirstsunday;
var ftrgt = TargetUrl;
while (Ftrgt.indexof ("") >= 0) Ftrgt = ftrgt.replace ("'", "'");
while (Ftrgt.indexof ("") >= 0) Ftrgt = ftrgt.replace ("'", "\ \");
var obuf = ' <table border= ' 0 "width=" 100% "cellspacing=" 0 "cellpadding=" 0 ">";
Obuf + = ' <tr><td class= ' Calendarhd "><a href=" Javascript:showcalendar (\ ' + Targetid + "', '" + FTrgt + "'," + (dMonth-1) + ', ' + Dyear + ', 90); " ></a></td > ';
Obuf + + <td colspan= "5" class= "CALENDARHD" > ' + (calendar_monthnames[dmonth]) + ' + dyear + ' </TD> ';
Obuf + = ' <td class= ' CALENDARHD ' ><a href= ' Javascript:showcalendar (\ ' + Targetid + "', '" + Ftrgt + "'," + (DMonth + 1) + ', ' + Dyear + ', 90; ></a></td ></TR> ';
Obuf = ' <tr style= ' calendarhdrow ' > ';
for (Var e=0 e < 7; e++) Obuf + = ' <td class= ' calendardays ' > ' + calendar_daynames[e] + ' </TD> ';
Obuf + = ' </TR> ';
var nextmonthfirstday = new Date (Dyear, dmonth+1, 1);
var isnextmonthfirstdaysunday = Nextmonthfirstday.getday () ==0;
for (var irows=0; irows < 6; irows++)
{
Dcurrentmonthdate = new Date (Dcurfd.getfullyear (), Dcurfd.getmonth (), dcurfd.getdate () + idays);
if (1==1)
{
if (irows==5 && dcurrentmonthdate.getmonth () > Dcurfd.getmonth ()) continue;
if (irows==5 && isnextmonthfirstdaysunday) continue;
Obuf = ' <tr class= ' calendarcontent ' > ';
for (var icols=0; icols < 7; icols++)
{
Dcurrentviewdate = new Date (Dcurfd.getfullyear (), Dcurfd.getmonth (), dcurfd.getdate () + idays);
if ((dgivendate.todatestring () = = Dcurrentviewdate.todatestring ()) && (DDay!= 90))
{
Obuf = ' <td class= ' selectedDate ' > ';
}
Else
{
if (Dcurrentviewdate.getmonth ()!= Dmonth | | idays < 0)
{
Obuf = ' <td class= ' negdate ' > ';
}
Else
{
Obuf = ' <td class= ' posdate ' > ';
}
}
var args;
if (targeturl.substr (0,11) = = ' javascript: ')
{
args = dcurrentviewdate.valueof () + ")";
}
Else
{
var sep = targeturl.indexof ('? ') < 0? '? ': ' & ';
args = Sep + ' startdate= ' + dcurrentviewdate.getfullyear () + '-' + (Dcurrentviewdate.getmonth () +1) + '-' +dcurrentviewdate. GetDate ();
}
Obuf + = ' <a href= ' + targeturl + args + ' > ' + dcurrentviewdate.getdate () + ' </A></TD> ';
idays++;
}
Obuf + = ' </TR> ';
}
}
Obuf + = ' </TABLE> ';
document.getElementById (targetid). InnerHTML = Obuf;
}
Call
<link href= "Global.css" rel= "stylesheet" >
<script type= "Text/javascript" src= "Global.js" ></script>
<div id= "Calendar1" class= "Calendar" ></div>
<script type= "Text/javascript" >
var dnow = new Date ();
Showcalendar (' Calendar1 ', filename.aspx ', Dnow.getmonth (), Dnow.getfullyear (), Dnow.getdate ())
</script>