Click to See Complete Forum and Search --> : troube with date and calendar


pixelmech
01-06-2004, 09:53 AM
Hello,

Trying to build a calendar and having trouble with the beginning of the month. You can see the page with the inline JS here:

http://www.pixelmech.com/review/myCal.html

Everything is fine except I cannot get the correct day to start on the correct date. I.e. , January 2004 starts on thursday, the 1st.

I end up with it starting on thursday okay, but on the 5th. I think my problem is this snippet:


// if date is not yet on correct DAY, write a blank
if(currentDay.getDate() <= firstDay.getDay())
{
calHTML += "&nbsp;";
}
// otherwise write out the date
else
{
calHTML += currentDay.getDate();
}
// this line is the trouble I think - moving it into the ELSE clause = infinte loops
currentDay.setDate(currentDay.getDate() + 1);


Moving the date iterator inside the else causes an infinte loop. But keeping it in there ticks off the dates, so I always end up starting with a date later than 1 (depending on how many blank days). Any help is appreciated.

Thanks

Tom

jaegernaut
01-06-2004, 12:55 PM
Here is the change that I made and it seems to work:


// is the column correct for the Day
if(i == currentDay.getDay())
{
// if so write date
calHTML += currentDay.getDate();
currentDay.setDate(currentDay.getDate() + 1);
}
// otherwise write a blank
else
{
calHTML += "&nbsp;";
}


See if this fixes the issue for you.

pixelmech
01-06-2004, 01:09 PM
Jug I think your solution was close to mine. I ended up just adding another variable for the 'current cell' and checking that.

Let me know if it works (anyone who wants to test it) - here it is:

http://www.pixelmech.com/review/myCal.html

jaegernaut
01-06-2004, 01:17 PM
Yep, I think we are basically doing the same thing.

I used the i variable you were already using vs. creating another variable and adding the iteration lines, but yours seems to work fine.

I checked a couple of different months, and they seem to display correctly, so I think you are good to go.

Good work!