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">
<!-- 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;
var lastday=dd.getDate();

var sd=d.getDay();

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

document.write("<TABLE BORDER width=\"50%\" cellwidth=\"14%\" CELLpadding=8>");
var y=1;
for ( x=0; x < sd ; x++) {
for ( x=sd; x < lastday + sd; x++) {
document.write("<TD width=\"100\" >" +   $bstart + y + $bend  + "<\/td>");
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="";}
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;

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

// and this should look like this -->

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?

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

Any inaccuracies in this index may be explained by the fact that it has been sorted with the help of a computer. (Donald Knuth)

This post tagged: