View Full Version : Can onclick image swap change different image?

12-11-2007, 11:45 PM
Hi, I'm very new to java; about the only thing I know how to do successfully are onmouseover events. I've been searching for an hour on many different sites and I haven't found the answer to my question.

I'm creating an image gallery and I am currently using an iframe and the target command to have the full-size images appear on the page without having to reload it. I would like to, instead, start off with a blank image and, when the user clicks on an icon, have that blank image swap to the full-size version of the icon. Is this possible?

To reiterate, is it possible to click on icon1.jpg and cause that to swap pictureA.jpg with pictureB.jpg?

Any help would be greatly appreciated.

12-12-2007, 12:31 AM

That might be a nice thing for you to try. It's easy and free, and works great. I see a lot of sites that use it.

12-12-2007, 12:37 AM
Wow, that's... pretty amazing. Thanks a lot! :)

12-12-2007, 05:53 PM
You first need to preload the images that are swapped in/out:

var im1 = new Image(); im1.src = "image1.jpg";
var im2 = new Image(); im2.src = "image2.jpg";
Then you need to identify the target image:

<img id="target" src="blank.jpg" />
Now your clickable image should have a onclick event attached:

<a href="#" onclick="target.src=im1.src; return false;"><img src="icon1.jpg" /></a>

<a href="#" onclick="target.src=im2.src; return false;"><img src="icon2.jpg" /></a>

John Rostron

12-12-2007, 06:40 PM
its possible with javascript.. very simple just check in jscript tutorial. You can get bult in script also for all this. m also doing like this for one of my site

12-12-2007, 09:52 PM
thanks for all the advice, it's working great!