APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

JavaScript Calendar

This is a Javascript calendar program. If you don't have Javascript enabled, or if your browser doesn't support Javascript, you won't see anything but this message. It's not terribly difficult to extend this so that it becomes a web based scheduler, an in-out board, or anything else.





Javascript is not Java. Javascript is a scripting language developed by Netscape, and really has nothing to do with Java. Javascript isn't cgi-bin programming, either. The script is actually in the HTML page. You can't see it if you "View Source"; all you'd see is the HTML tags and text that the Javascript program produced. Here you can see what is really going on.


<script language="JavaScript" type="text/javascript">
//<![CDATA[
<!-- yes this should look like this

function calendar() {
var now=today.getDate();
var tmonth=today.getMonth();
var tyear=today.getYear();
if (tyear < 1000) {tyear += 1900};
var d=new Date(year,month,"1");
var dd=new Date(year,nextmonth,"1");
var aday=(1000 * 60 * 60 * 24);
var ms=dd.getTime();
ms -= aday;
dd.setTime(ms);
var lastday=dd.getDate();

var sd=d.getDay();
pmonth=month-1;
pyear=year;
nmonth=month+1;
nyear=year;

if (pmonth < 0) { pmonth=11; pyear--;}
if (nmonth > 11) {nmonth=0; nyear++;}
dnmonth=nmonth+1;
dpmonth=pmonth+1;
document.write("<h2>Calendar for  ");
document.write(names[month] + " " + year);
document.write("<\/h2>");



document.write("<TABLE BORDER width=\"50%\" cellwidth=\"14%\" CELLpadding=8>");
var y=1;
document.write("<TR>");
document.write("<td>S<\/td><td>M<\/td><td>T<\/td><td>W<\/td><td>T<\/td><td>F<\/td><td>S<\/td><\/tr><tr>");
for ( x=0; x < sd ; x++) {
        document.write("<TD><\/TD>");
}
t=sd; 
 
for ( x=sd; x < lastday + sd; x++) {
document.write("<TD width=\"100\" >" +   $bstart + y + $bend  + "<\/td>");
y++;t++;
if ((t % 7) == 0) { document.write("<\/TR><tr>")}; 
if (y == now && tmonth==month && tyear == year) { $bstart="<b><font color=\"blue\"> ";$bend="<\/font><\/b>"; } else
{ $bstart="";$bend="";}
}
document.write("<\/TR><TR>");
document.write("<\/table>");
}
var today=new Date();

var month=today.getMonth();
var nextmonth=month+1;
var year=today.getYear();
if (year < 1000) {year += 1900};
if (nextmonth > 12) {nextmonth=1};month;

$bstart="";
$bend="";
names=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var x=0;
calendar();

// and this should look like this -->
//]]>
</script>
 



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Javascript CalendarProgram




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





I love deadlines. I love the whooshing noise they make as they go by. (Douglas Adams)

When Life Gives You Questions, Google has Answers (AJ Carpio)












This post tagged: