Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2011, 03:27 PM   PM User | #1
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
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
javanewbie7 is offline   Reply With Quote
Old 11-02-2011, 03:45 PM   PM User | #2
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
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?
javanewbie7 is offline   Reply With Quote
Old 11-02-2011, 05:41 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 11-03-2011, 02:37 AM   PM User | #4
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
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@
javanewbie7 is offline   Reply With Quote
Old 11-08-2011, 02:58 PM   PM User | #5
javanewbie7
Regular Coder

 
Join Date: Oct 2010
Posts: 121
Thanks: 25
Thanked 0 Times in 0 Posts
javanewbie7 is an unknown quantity at this point
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!
javanewbie7 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.