I have a function that uses document.write to generate html elments on my page. The problem is when I call the function, all my other functions and html is lost. I was reading that I can use innerhtml to prevent this. I've never used innerhtml before. Can anyone explain how I can use innerhtml in my function to prevent from losing all my other functions and html on my page?
Here is my javascript functions:
function PrevMonth() {
var p = new Date();
p.getMonth();
p.setMonth(p.getMonth()-1)
;
return p.getMonth();
}
function NextMonth() {
var n = new Date();
n.getMonth();
n.setMonth(n.getMonth()+1)
;
return n.getMonth();
}
function PrevYear() {
var p = new Date();
p.getYear();
p.setYear(p.getFullYear()-
1);
return p.getYear();
}
function NextYear() {
var n = new Date();
n.getYear();
n.setYear(n.getFullYear()-
1);
return n.getYear();
}
function daysInMonth(myDate) {
var c = new Date(myDate);
c.setDate(28);
while(c.getMonth() == myDate.getMonth()) {
c.setDate(c.getDate()+1);
}
c.setDate(c.getDate()-1);
return c.getDate();
}
function Calendar() {
var day_name = new Array(7)
day_name[0] = "Sun"
day_name[1] = "Mon"
day_name[2] = "Tue"
day_name[3] = "Wed"
day_name[4] = "Thu"
day_name[5] = "Fri"
day_name[6] = "Sat"
var month_name = new Array(12)
month_name[0] = "January"
month_name[1] = "February"
month_name[2] = "March"
month_name[3] = "April"
month_name[4] = "May"
month_name[5] = "June"
month_name[6] = "July"
month_name[7] = "August"
month_name[8] = "September"
month_name[9] = "October"
month_name[10] = "November"
month_name[11] = "December"
var Date_Object = new Date()
Date_Object.setMonth(2);
var current_day = Date_Object.getDay()
var current_month = Date_Object.getMonth()
var current_year = Date_Object.getYear()
if (current_year < 2000) {
current_year += 1900
}
var total_days = daysInMonth(Date_Object);
var first_day = (current_day - Date_Object.getDate() + 7) % 7 + 1;
var rows = (first_day + total_days) / 7
var pos = 0
document.write("<table border='1'><tr><td colspan='7'><a href='javascript:;' onClick='PrevMonth();'><<<
/a> " + month_name[current_month] + " <a href=''>>></a> <a href=''><<</a> " + current_year + " <a href=''>>></a></td><tr>")
document.write("<tr><td colspan='7'>" + month_name[current_month] + " " + current_year + "</td></tr>")
document.write("<tr>")
for(x = 0; x <= 6; x++) {
document.write("<td>" + day_name[x] + "</td>")
}
document.write("</tr>")
for(r = 0; r < rows; r++) {
document.write("<tr>")
for(d = 0; d <= 6; d++) {
pos++;
if ((pos > first_day) && (pos <= total_days + first_day))
document.write("<td><a href=''>" + (pos - first_day) +"</a></td>")
else
document.write("<td> </td>")
}
document.write("</tr>")
}
document.write("<tr><td colspan='7'>hours:minutes:
seconds AM/PM</td></tr>")
document.write("</table>")
}
When I call Calender() all my other functions are lost.
Thanks for any help.
Regards,
-D-
View the Solution FREE for 30 Days