Hi there, im trying to write a javascript calendar.... my code wont work! can someone please look and tell me what the problem is - im kinda new, so I know my code wont be the best, and tne mistake is probably obvious.... but i just want to get the javascript to at least write my table header to a web page! here it is: (PLEAAAAAAAAAAAAASE HELP!)
<head>
<title>CS2003 Practical 1</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
var Calendar = new Date();
var year = Calendar.getYear(); // Returns year
var month = Calendar.getMonth(); // Returns month (0-11)
var today = Calendar.getDate(); // Returns day (1-31)
var weekday = Calendar.getDay(); // Returns day (0-6)
var DAYS_OF_WEEK = 7; // "constant" for number of days in a week
var DAYS_OF_MONTH = 31; // "constant" for number of days in a month
var days_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function text_month(){
if (month == 0){
return ("Jan");
} else if (month == 1){
return ("Feb");
} else if (month == 2){
return ("Mar");
} else if (month == 3){
return ("Apr");
} else if (month == 4){
return ("May");
} else if (month == 5){
return ("Jun");
} else if (month == 6){
return ("Jul");
} else if (month == 7){
return ("Aug");
} else if (month == 8){
return ("Sept");
} else if (month == 9){
return ("Oct");
} else if (month == 10){
return ("Nov");
} else if (month == 11){
return ("Dec");
}
}
function start_day(){
var firstOfMonth = new Date (year, month, 1); // Create a new date, for the first of "month"
var firstDay = firstOfMonth.getDay(); // Use getDay method to find the day.
if (firstDay == 0){
return (days_of_week[0]);
} else if (firstDay == 1){
return (days_of_week[1]);
} else if (firstDay == 2){
return (days_of_week[2]);
} else if (firstDay == 3){
return (days_of_week[3]);
} else if (firstDay == 4){
return (days_of_week[4]);
} else if (firstDay == 5){
return (days_of_week[5]);
} else if (firstDay == 6){
return (days_of_week[6]);
}
}
function getDaysInMonth(year, month){
var nextDate = new Date(year, month+1, 0); // Get the "zeroth" day of the next month to find the number of days in the month. (IE only)
return nextDate.getUTCDate();
}
function tableHeader(){
document.write("<h1> HELLO PLEASE BE ABLE TO SEE THIS</h1>");
document.write("<center>");
document.write("<table border=2 cellspacing=0 cellpadding=0 width=500>");
document.write("<tr><td width=100% colspan=7>Feb 2002</td></tr>");
document.write("<tr>");
document.write("<td width=14%>Sun</td>");
document.write("<td width=14%>Mon</td>");
document.write("<td width=14%>Tue</td>");
document.write("<td width=14%>Wed</td>");
document.write("<td width=14%>Thurs</td>");
document.write("<td width=14%>Fri</td>");
document.write("<td width=14%>Sat</td>");
document.write("</tr>");
}
function pad(){
if (start_day() == "Mon"){
document.write("<td width=14%></td>");
} else if ((start_day() == "Tue"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Wed"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Thurs"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Fri"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
} else if ((start_day() == "Sat"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Sun"){
// Blank
}
}
function table_body(){
var date_value = 1;
var i;
var counter;
if (start_day() == "Mon"){
counter = 6;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Tue"){
counter = 5;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Wed"){
counter = 4;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Thurs"){
counter = 3;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Fri"){
counter = 2;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Sat"){
counter = 1;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Sun"){
counter = 0;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
}
}
function table_footer(){
}
//-->
</script>
</head>
<body onload="tableHeader()">
</body>
<head>
<title>CS2003 Practical 1</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
var Calendar = new Date();
var year = Calendar.getYear(); // Returns year
var month = Calendar.getMonth(); // Returns month (0-11)
var today = Calendar.getDate(); // Returns day (1-31)
var weekday = Calendar.getDay(); // Returns day (0-6)
var DAYS_OF_WEEK = 7; // "constant" for number of days in a week
var DAYS_OF_MONTH = 31; // "constant" for number of days in a month
var days_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function text_month(){
if (month == 0){
return ("Jan");
} else if (month == 1){
return ("Feb");
} else if (month == 2){
return ("Mar");
} else if (month == 3){
return ("Apr");
} else if (month == 4){
return ("May");
} else if (month == 5){
return ("Jun");
} else if (month == 6){
return ("Jul");
} else if (month == 7){
return ("Aug");
} else if (month == 8){
return ("Sept");
} else if (month == 9){
return ("Oct");
} else if (month == 10){
return ("Nov");
} else if (month == 11){
return ("Dec");
}
}
function start_day(){
var firstOfMonth = new Date (year, month, 1); // Create a new date, for the first of "month"
var firstDay = firstOfMonth.getDay(); // Use getDay method to find the day.
if (firstDay == 0){
return (days_of_week[0]);
} else if (firstDay == 1){
return (days_of_week[1]);
} else if (firstDay == 2){
return (days_of_week[2]);
} else if (firstDay == 3){
return (days_of_week[3]);
} else if (firstDay == 4){
return (days_of_week[4]);
} else if (firstDay == 5){
return (days_of_week[5]);
} else if (firstDay == 6){
return (days_of_week[6]);
}
}
function getDaysInMonth(year, month){
var nextDate = new Date(year, month+1, 0); // Get the "zeroth" day of the next month to find the number of days in the month. (IE only)
return nextDate.getUTCDate();
}
function tableHeader(){
document.write("<h1> HELLO PLEASE BE ABLE TO SEE THIS</h1>");
document.write("<center>");
document.write("<table border=2 cellspacing=0 cellpadding=0 width=500>");
document.write("<tr><td width=100% colspan=7>Feb 2002</td></tr>");
document.write("<tr>");
document.write("<td width=14%>Sun</td>");
document.write("<td width=14%>Mon</td>");
document.write("<td width=14%>Tue</td>");
document.write("<td width=14%>Wed</td>");
document.write("<td width=14%>Thurs</td>");
document.write("<td width=14%>Fri</td>");
document.write("<td width=14%>Sat</td>");
document.write("</tr>");
}
function pad(){
if (start_day() == "Mon"){
document.write("<td width=14%></td>");
} else if ((start_day() == "Tue"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Wed"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Thurs"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Fri"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
} else if ((start_day() == "Sat"){
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
document.write("<td width=14%></td>");
}
} else if ((start_day() == "Sun"){
// Blank
}
}
function table_body(){
var date_value = 1;
var i;
var counter;
if (start_day() == "Mon"){
counter = 6;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Tue"){
counter = 5;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Wed"){
counter = 4;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Thurs"){
counter = 3;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Fri"){
counter = 2;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Sat"){
counter = 1;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
} else if ((start_day() == "Sun"){
counter = 0;
for (i = 0; i <= counter; i++){
document.write("<td width=15%>i</td>");
}
}
}
function table_footer(){
}
//-->
</script>
</head>
<body onload="tableHeader()">
</body>