Results 1 to 2 of 2

Thread: Difficult Javascript Problem!

  1. #1
    Join Date
    Oct 2005
    Posts
    39

    Exclamation Difficult Javascript Problem!

    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

  2. #2
    Join Date
    Mar 2004
    Location
    China
    Posts
    3,315
    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.

Posting Permissions

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