PDA

View Full Version : Difficult Javascript Problem!



ecampsite.co.uk
06 Dec 2005, 02:05 PM
Hi guys,

Here's one to rack your brains over.

I want to use a javascript in order to change the color of some text depending on the current date. For example, i want to define 2 dates, and if the current date is within those 2 dates it displays one colored text and if it is outside that date it displays a different colored text.

To get an example of what i mean go to www.ecampsite.co.uk/somerset.php

If a campsite is open, the text will be green, and if it is closed it is orange. Is there any way to automate this with javascript??

Your input regarding this will be invaluable!

Thank you

Craig

Rincewind
07 Dec 2005, 08:12 AM
Yes you could do it with javascript. It's not, dispite your title, difficult. Just look up date functions in javascript and you'll see how to compair them. The it's just a matter of a simple if statement to change the colour.

However, I'd do it like the site you mensioned does. I'd use PHP rather than javascript. The php runs server side where as the javascript runs client side so it removes the possibility of the client having javascript turned off and getting all sites marked closed or open when they are not really.