Click to See Complete Forum and Search --> : Image at time
skiddaire
04-10-2003, 04:08 AM
hey guys, looking for a script that will show an image at certain time of day e.g
morning
afternoon
evening
i want to do 3 diff banners/logos for my site. i have the welcome script (Good Morning! etc) but can't find one for the image at time
anyone help?
cheers
Chris
SniperX
04-10-2003, 04:21 AM
Just get the time and switch the hours
ie (time > 6 && time < 12 ) diplay morning gif
and so on
skiddaire
04-10-2003, 06:38 AM
can you make up the script for me as i'm crap at stuff like that :)
this is the script that i found for the wording
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// End -->
</script>
so how would i edit that to bring up images?
would it be like display = "morning.gif";
or what?
i dont; knwo much javascript so any help would be greatful :cool:
SniperX
04-10-2003, 07:03 AM
Im not too sure but this should work...
<html>
<SCRIPT LANGUAGE="JavaScript">
<!--
source = new Array("night.jpg", "afternoon.jpg", "morning.jpg");
function checkDate() {
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18){ display = "Evening"; document.getElementById("test").src=source[0];}
else if (thehour >12) {document.getElementById("test").src=source[1]; }
else {display = "Morning"; document.getElementById("test").src=source[2];}
}
-->
</script>
<body onLoad="checkDate()">
<img id="test" src="morning.jpg">
</body>
</html>
Hope it helps you - how long have u been doing javascript?
And where are you from?
If you dont mind answering.
Regards MW
skiddaire
04-10-2003, 10:09 AM
not long really, i mostly find all i need on javascriptsource.internet.com but couldnt; find the one that i needed.
i'm from the good ole uk heh
will try that code tonight, keep you posted ;)
SniperX
04-10-2003, 11:40 PM
Hope it workx
skiddaire
04-11-2003, 12:41 AM
yeah it looks like it works, i made up a test page and changed the system time to see if it changed the images and it did :) thanks sniperx :D ur the best
SniperX
04-11-2003, 12:43 AM
Your crazy - i cant be da best - iv only been doing javascript since i joined this forum.
Thats not too long, i think a week or two
You do any other languages?
I do C/C++ a bit of perl, cgi scripting and intermediate java
skiddaire
04-11-2003, 12:47 AM
nope, nothing else, i'm a true lazy bugger :)
SniperX
04-11-2003, 12:51 AM
So you are a true lazy bugger....
What do you do?
Student? or what?
How old are you?
Male or Female?
web-eagle
04-14-2003, 12:56 AM
Ok, I think I get it.
But I think I also see an error. I’m not trying to be a smart a**, I was just cruising the threads, and now I just want to know if I understand what I think I understand.
<SCRIPT LANGUAGE="JavaScript">
<!--
source = new Array("night.jpg", "afternoon.jpg", "morning.jpg");
function checkDate() {
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18){display = "Evening"; document.getElementById("test").src=source[0];}
else if (thehour >12) {display = "Afternoon"; document.getElementById("test").src=source[1]; }
else {display = "Morning"; document.getElementById("test").src=source[2];}
}
-->
</script>
Should make the word “Afternoon” appear for hours from 12 to 18, right?
And If I wanted just the picture without any words at all, would I do this?
if (thehour > 18) {display = document.getElementById("test").src=source[0];}
else if (thehour >12) {display = document.getElementById("test").src=source[1]; }
else {display = document.getElementById("test").src=source[2];}
And finally, if I wanted more images, I would simply add them to the Array, yes?
source = new Array("night.jpg", “teatime.jpg”, “naptime.jpg”, "afternoon.jpg", “coffeetime.jpg”, "morning.jpg");
Thanks in advance for your help
SniperX
04-14-2003, 01:00 AM
I left that bit out because i was testing in the afternoon and was to lazy to insert that bit back.
You can do what ever you like, just so long that it works
Regards
MW
skiddaire
04-14-2003, 12:32 PM
lol sniper x, its alright csalling me a lazy bugger but ur the same :D
i'm a student, am 17 do webdesign blah
male