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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Displaying image by time

    Hello all....

    I have a rotator on my site and I'm trying to set it up to where it will display certain images at 7p, 8p, 9p....and then the rest of the time it rotates as normal.

    I looked online and found this script....

    Code:
    <script type="text/javascript">
    <!--
    var varTime = new Date(); // creates a new date object
    var varDayNight = varTime.getHours(); // gets the time of the day in hours
    
    if (varDayNight >= 6 && varDayNight <= 18 ) { // after 6am & before 6pm
    document.write ("<img src='../../_assets/day.jpg' width='500' height='375' alt='Weclome to another day'>");
    }
    else {
    document.write ("<img src='../../_assets/night.jpg' width='500' height='375' alt='Weclome to the night'>");
    }
    //-->
    </script>
    Here's my link:

    http://tinyurl.com/3n6plwh


    Now obviously that wouldn't work with my rotator, but it helped me get started.. I changed a couple of things, but it's still not working.

    One problem is I don't have an idea of what to to put for "else" to have all the images rotate if it's not one of these times. The other problem is despite changing the if statements to

    Code:
    var varDayNight = varTime.getHours(); // gets the time of the day in hours
    if (varDayNight  >= 9 && varDayNight <= 10) { 
    
    document.getElementById("bbpage2");
    
    }
    
    if (varDayNight  >= 20 && varDayNight <= 21) { 
    
    document.getElementById("bbpage3");
    
    }
    
    if (varDayNight  >= 21 && varDayNight <= 22 ) { 
    
    document.getElementById("bbpage4");
    
    }
    
    else {
    
    }
    It Still won't display the correct image. Any help?

    *Note I have the first image displaying at 9a because that's the current time. I'll eventually change it to 7p or 19 later

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    I found one issue...I changed my if statements to

    Code:
    if (varDayNight  >= 9 && varDayNight <= 10) { 
     document.getElementById("bbpage2").src="http://www.kacvtv.org/rotatorpics/lopezftf.jpg";
    }
    But it's still not working. Any ideas?

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,733
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    The link appears to be broken. Nothing displays in the browser.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    The link appears to be broken. Nothing displays in the browser.
    Really? I;ve checked it on three different computers (and all browsers) and it's working for me.

    I'll take a look tomorrow at work and might try re-uploading it. Thanks@

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Sorry it took so long. It's been hectic.

    Here's a new link.:

    Link


    I should add that the rotator was created using JQuery. So this may need to move to the JQuery forum. THanks again!


  •  

    Posting Permissions

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