/    Sign up×
Community /Pin to ProfileBookmark

Java image change to time

Hi, befor i start you should know that i have little knowledge of javascript…?

i found this and it works fine, but can some please help as i want to add a 3rd image! i have tried a few things but failed. any help would be great!!!!

/* This script and many more are available free online at
The JavaScript Source!! [url]http://javascript.internet.com[/url]
Created by: Anonymous | [url]http://musikimiz.googlepages.comLicensed[/url] under: Creative Commons License
*
/

function pixTimeChange() {
var t=new Date();
var h = t.getHours();
var r1=”pic1.gif”;
var r2=”pic2.gif”;
var el=document.getElementById(‘myimage’);

// See the time below. Note: The time is in 24 hour format.
// In the example here, “7” = 7 AM; “17” =5PM.
el.src = (h>=7 && h<17) ? r1 : r2;
}

// Multiple onload function created by: Simon Willison
// [url]http://simonwillison.net/2004/May/26/addLoadEvent/[/url]
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
pixTimeChange();
});

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cridleyAug 20.2008 — Hi,

surely just add an image

var r3="pic3.gif";

and set that depending on the time :

if (h>=7 && h<17)

el.src = r1;

else if (h<23)//this is whatever criteria you want

el.src = r2;

else

el.src = r3;

or

el.src = (h>=7 && h<17) ? r1 : ((h<23)?r2:r3);
×

Success!

Help @bajere spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...