[thelist] javascript: date trouble

Chris Hayes chris at londonweb.net
Tue Jan 6 11:19:22 CST 2004


It will infinite loop as the increment code will never be run (when placed
inside the else clause).

Try building your space-padding code outside of the main loop using getDay()
, similarly you can determine which day it is at the end of the month and
add space-padding to the end of the date output.




----- Original Message ----- 
From: "Tom Dell'Aringa" <pixelmech at yahoo.com>
To: <thelist at lists.evolt.org>
Sent: Tuesday, January 06, 2004 3:51 PM
Subject: [thelist] javascript: date trouble


> 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 outside 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).
>
> Thanks
>
> Tom
>
> =====
> http://www.pixelmech.com/ :: Web Development Services
> http://www.DMXzone.com/ :: JavaScript Author / Every Friday!
> http://www.thywordistruth.net/ :: Eternal Life
>
> [Those who say that I am finished, and am through, will have to run over
my dead body to beat me...]
> -- 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !



More information about the thelist mailing list