...

View Full Version : document.write where I want it



ScottInTexas
06-27-2006, 04:09 AM
I have this code to write a calendar. But I want it written in a div I have set aside.



function writeIt(){
document.write(TheMonth());
document.write("<table border='1px'>");
document.write("<tr><th colspan='7'></th></tr>");
document.write("<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>");
var offset=getFirstOfMonth();
var lastDay=getLastOfMonth();
document.write("<tr>");
for(var i=0;i<=offset-1;i++){
document.write("<td></td>");
}
for(i=offset+1;i<=(lastDay+offset);i++){
document.write("<td>"+(i-offset)+"</td>");
if(i%7==0)document.write("</tr><tr>");
}
document.write("</table>");
}

And the div is defined as;


<div id="calendargrid">
<script type="text/javascript">
writeIt()
</script>
</div>

the reason I'm doing this is so that I can have interactive calendars without writing asp (cause I don't know php). Besides, this is suppposed to be a throw down easy web page!

Thanks for your help.

_Aerospace_Eng_
06-27-2006, 04:38 AM
Okay so what is the problem?

ScottInTexas
06-27-2006, 01:10 PM
When the window first comes up it writes the calendar for the current month as it should. I have a row of months abve it in another div whcich the user can select Jan-Dec. When the user clicks on another month a function returns the month chosen in the var month and then writeIt() is called. When writeIt is called the screen is completely re written and I just want it to write the new calendar to the calendar div leaving the row of months and the left column alone.

Beagle
06-27-2006, 04:14 PM
You would probably find the non-standard innerHTML property on the DIV more useful than document.write

Create a string for your html:

var cal = "<table><tr><td></td></tr></table>";

Then assign it to the div's innerHTML:

document.getElementById('calDiv').innerHTML(cal);

ScottInTexas
06-28-2006, 02:43 AM
I get an error that says object doesn't support this action.

_Aerospace_Eng_
06-28-2006, 09:31 AM
Post the code you tried please.

arnyinc
06-28-2006, 02:36 PM
This line:

document.getElementById('calDiv').innerHTML(cal);

Should be:

document.getElementById('calDiv').innerHTML=cal;

ScottInTexas
06-28-2006, 07:26 PM
That was it! I thank you all for your help. I wouldn't know what to do without this forum!

Beagle
06-29-2006, 04:49 PM
Ha, wow, yeah, sorry about that. Must've been really tired when I wrote that. Glad you got it worked out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum