Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Southport, CT
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Load a .js file depending on Day of the Year

    I am fairly new to JavaScript, but have been able to figure a lot out, but what I have been trying to do for three weeks is this: on my website: www.southportvfd.com, I have a counter that counts up from the date the Fire Department was establish October 2, 1895. The months, days, hours, minutes, and seconds are fine, but the YEAR field also comes from the time of the local user. So since we were established on Oct 2, 1895, we have not been around for 109 years until Oct 2, 2004 . . . but since it has been 109 years since Jan 1 1895, the counter says 109 years. My solution is that I made 2 files: myclock.js (which counts from 1895), and myclock_.js (which counts from 1894)

    I AM LOOKING FOR: a JavaScript that will load "/js/myclock.js" if the current date is Oct 2 through Dec 31, and load "/js/myclock_.js" if the current date is Jan 1 through Oct 1.

    PLEASE HELP

    -Romsky

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    var script = document.createElement("script")
    script.setAttribute("type","text/javascript");

    //determine js file
    var today = new Date();
    var mm = today.getMonth(); //this starts at 0
    var jsFile = (mm<9 || (mm==9 && today.getDate()==1)) ? "/js/myclock_.js" : "/js/myclock.js"

    script.setAttribute("src", jsFile);
    document.getElementsByTagName("head")[0].appendChild(script);

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Obviously, the script is not acurately calculating the years/monthes/days. And since that script is over bloated at 10086 characters and 749 lines. I would suggest finding another script. You may find one here by searching the forums.

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Location
    Southport, CT
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much glenngv, I really appreciate you taking the time to help me out.

    Willy Duitt:
    It was pretty difficult to find a script that counted up from a specific date down to the second, and used custom images to do it. If you have a better script to use, I am open to change, but as long as what I'm using now works, I'm going to stick with it.


  •  

    Posting Permissions

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