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

JavaScript Calendar


© December 1997 Tony Lawrence

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


Inexpensive and informative Apple related e-books:

Take Control of High Sierra

Photos for Mac: A Take Control Crash Course

Photos: A Take Control Crash Course

Take Control of Pages

Take Control of Automating Your Mac




More Articles by © Tony Lawrence




Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





The errors which arise from the absence of facts are far more numerous and more durable than those which result from unsound reasoning respecting true data. (Charles Babbage)




Linux posts

Troubleshooting posts


This post tagged:

Code

Javascript



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode





SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)
www.SCOsales.com