By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Switch between images

P: n/a
I´m trying to find out how to switch between an image by a mouseclick.

The function should check if the image is on or off but it doesn´t work.
What´s wrong?

Below the script.

start_on = new Image;
start_on.src = "images/start_on.jpg";
start_off = new Image;
start_off.src = "images/start_off.jpg";

function switch(image) {
document.images[image].src = (document.images[image].src.indexOf("_off")==-1)? eval(image + "_off.src"); eval(image + "_on.src")
}

<img border="0" name="start" src="images/start_on.jpg" onClick="switch('start')">

Thanks
John

http://members.home.nl/jpeskens
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"John" <jp**********@spamhome.nl> schreef in bericht news:bo**********@news4.tilbu1.nb.home.nl... I´m trying to find out how to switch between an image by a mouseclick.

The function should check if the image is on or off but it doesn´t work.
What´s wrong?


document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";

JW

Jul 20 '05 #2

P: n/a

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f***********************@news.wanadoo.nl...

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";


Error, sorry. Should be:

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
start_off.src : start_on.src;
JW


Jul 20 '05 #3

P: n/a
Hoi Janwillem,
Ik heb het al gezien. Het lag aan de puntkomma. Moet een dubbele punt zijn.

Bedankt in ieder geval

John

htpp://members.home.nl/jpeskens
"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht news:3f***********************@news.wanadoo.nl...

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f***********************@news.wanadoo.nl...

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
image + "_off.src" : image + "_on.src";


Error, sorry. Should be:

document.images[image].src =
(document.images[image].src.indexOf("_off")==-1) ?
start_off.src : start_on.src;


JW



Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.