Advanced Search

Results 1 to 3 of 3

Thread: Code to check date then do action

  1. #1
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Code to check date then do action

    I'm building an advent calendar and am not au fait with flash. I need code that will check date (PC set date will do) then perform set action depending on date. Anyone any ideas? I'll post this in dhtml too.
    many thanks
    M

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,699
    Thanks
    43
    Thanked 3,132 Times in 3,096 Posts
    Blog Entries
    12

    Default

    Here is a very simple javascript along the lines of what you propose:

    Code:
    <script type="text/javascript">
    var someDate=new Date()
    if(someDate.getMonth()+1==12&&someDate.getDate()==25){
    alert('Merry Christmas!')
    }
    </script>
    In place of the red line, you can have a more elaborate line(s) to perform more elaborate actions.

    In the first green line, the red numbers check for the month (12 for December) and date (25 for the 25th). You can have as many of these tests and subsequent actions as needed and it will probably be desirable to have the code be a function activated onload:

    Code:
    <script type="text/javascript">
    function advent(){
    var someDate=new Date()
    if(someDate.getMonth()+1==12&&someDate.getDate()==25){
    code for Christmas Day goes here
    }
    if(someDate.getMonth()+1==12&&someDate.getDate()==24){
    code for Christmas Eve goes here
    }
    if(someDate.getMonth()+1==12&&someDate.getDate()==18){
    code for something on December 18th could go here
    }
    }
    
    onload=advent;
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That's REALLY helpful - many many thanks! And I should say - i am NOT a student as profile suggests but a teacher! and a very busy one at that so I am VERy grateful!

Bookmarks

Posting Permissions

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