Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    document.write where I want it

    I have this code to write a calendar. But I want it written in a div I have set aside.

    Code:
    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;
    Code:
    	   <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.
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay so what is the problem?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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.
    Last edited by ScottInTexas; 06-27-2006 at 01:15 PM.
    Scott Stewart
    Always happy to learn from pros.

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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);

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I get an error that says object doesn't support this action.
    Scott Stewart
    Always happy to learn from pros.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post the code you tried please.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    This line:

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

    Should be:

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

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    That was it! I thank you all for your help. I wouldn't know what to do without this forum!
    Scott Stewart
    Always happy to learn from pros.

  • #9
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Ha, wow, yeah, sorry about that. Must've been really tired when I wrote that. Glad you got it worked out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •