...

View Full Version : Displaying a Calendar in Table form



ibleedart
05-03-2007, 10:32 AM
Okay, I've been working on this one all night and cannot figure out the problem, so I'm asking for help. I can't help but be vague at this point because I've racked my brain trying to figure out where I went wrong and have covered every angle I can think of. I'm doing this for a hw assignment and have followed all of the steps correctly according to the book, but for some reason, the calendar will not show up on this page. I've checked for errors, but I'm not getting any. Could someone please help me? :)



function writeCalTitle(calendarDay) {
var monthName=new Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
var thisMonth=calendarDay.getMonth();
var thisYear=calendarDay.getFullYear();
document.write('<tr><th id="calendar_head" colspan="7">'+monthName[thisMonth]+' '+thisYear+'</th></tr>');
}

function writeDayTitle() {
var wdName=new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
document.write("<tr>");
for(i=0; i<=6; i++) {
document.write('<th class="calendar_weekdays">'+wdName[i]+'</th>');
}
document.write("</tr>");
}

function writeCalDays(calendarDay) {
var thisDay=calendarDay.getDate();
calendarDay.setDate(1);
var weekDayNum=calendarDay.getDay();
document.write("<tr>");
for(num=0; num < weekDayNum; num++) {
document.write("<td></td>");
}
var cellCount=1;
var dayCount=1;
while(cellCount==dayCount) {
if(weekDayNum==0) {
document.write("<tr>");
}
if(dayCount==thisDay) {
document.write('<td class="calendar_dates" id="calendar_today">'+dayCount+'</td>');
} else {
document.write('<td class="calendar_dates">'+dayCount+'</td>');
}
if(weekDayNum==6) {
document.write("</tr>");
}
cellCount++;
calendarDay.setDate(cellCount);
dayCount=calendarDay.getDate();
weekDayNum=calendarDay.getDay();
}

function calendar(thisDate) {
if(thisDate=="today") {
var calDate=new Date();
} else {
var calDate=new Date(thisDate);
}
document.write('<table id="calendar_table">');
writeCalTitle(calDate);
writeDayTitle();
writeCalDays(calDate);
document.write("</tr></table>");
}
}


Here's the call to the function (it seems to me the quotes shouldn't be included for the parameters, but that's what the book said):

<script type="text/javascript">calendar("today");</script>

nikkiH
05-03-2007, 02:13 PM
There was an error; IE has to be set to display errors. FF, you have to open the console.
You have a bracket in the wrong spot.
It's missing from writeCalDays and stuck at the end of the script instead.

Oh, and using an editor that can "match brackets" is useful in finding these. I use EditPlus, personally.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum