Click to See Complete Forum and Search --> : Entire page javascript help


LauraAnn
10-22-2005, 10:40 AM
Hi. I'm new to javascript and am having problems. Here's my javascript code. Could anyone tell me if I am missing anything? It's supposed to create a calendar and highlight the current day. Thanks ahead of time!


/*
New Perspectives on HTML and XHTML
Case Problem 3

Name: Laura Todd
Date: 10/28/05
*/

function writeCatTitle(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">"thisMonth+" "+thisYear"");
}

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</th>");
}
document.write ("</tr>");
}

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

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

gph
10-22-2005, 11:32 AM
Most of the errors are string related. Specifically you need to understand the use of quotes.

Here is an example of one of the strings


// original
document.write ("<tr><th id="calendar_head" colspan="7">"thisMonth+" "+thisYear"");

// corrected
document.write ('<tr><th id="calendar_head" colspan="7">'+thisMonth+' '+thisYear);


A text editor with syntax highlighting would be a big help for you. There are lots of free and inexpensive editors out there. I suggest you search for an editor and tutorials on building javascript strings.

LauraAnn
10-22-2005, 01:14 PM
Thanks so much - hope it does the trick. :)