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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Displaying a Calendar in Table form

    Okay, I've been working on this one all night and cannot figure out the problem, so I'm asking for help. I can't help but be vague at this point because I've racked my brain trying to figure out where I went wrong and have covered every angle I can think of. I'm doing this for a hw assignment and have followed all of the steps correctly according to the book, but for some reason, the calendar will not show up on this page. I've checked for errors, but I'm not getting any. Could someone please help me?

    Code:
    function writeCalTitle(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">'+monthName[thisMonth]+' '+thisYear+'</th></tr>');
    }
    
    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[i]+'</th>');
       }
       document.write("</tr>");  
    }
    
    function writeCalDays(calendarDay) {
       var thisDay=calendarDay.getDate();
       calendarDay.setDate(1);
       var weekDayNum=calendarDay.getDay();
       document.write("<tr>");
       for(num=0; num < weekDayNum; num++) {
          document.write("<td></td>");
       }
       var cellCount=1;
       var dayCount=1;
       while(cellCount==dayCount) {
          if(weekDayNum==0) {
             document.write("<tr>");
          }
          if(dayCount==thisDay) {
             document.write('<td class="calendar_dates" id="calendar_today">'+dayCount+'</td>');
          } else {
             document.write('<td class="calendar_dates">'+dayCount+'</td>');
          }
          if(weekDayNum==6) {
             document.write("</tr>");
          }
          cellCount++;
          calendarDay.setDate(cellCount);
          dayCount=calendarDay.getDate();
          weekDayNum=calendarDay.getDay();
    }
    
    function calendar(thisDate) {
       if(thisDate=="today") {
          var calDate=new Date();
       } else {
          var calDate=new Date(thisDate);
       }
       document.write('<table id="calendar_table">');
       writeCalTitle(calDate);
       writeDayTitle();
       writeCalDays(calDate);
       document.write("</tr></table>");
    }
    }
    Here's the call to the function (it seems to me the quotes shouldn't be included for the parameters, but that's what the book said):
    Code:
    <script type="text/javascript">calendar("today");</script>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    There was an error; IE has to be set to display errors. FF, you have to open the console.
    You have a bracket in the wrong spot.
    It's missing from writeCalDays and stuck at the end of the script instead.

    Oh, and using an editor that can "match brackets" is useful in finding these. I use EditPlus, personally.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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