Forum Moderators: open

Message Too Old, No Replies

Image changer script

         

tintin99

2:35 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi,

I'm sure this question must have been asked several times already but I can't get the site search facility to work so I can't check.

I want to add some (simple) javascript to my site so I can click on a thumbnail image to change the main image on the page. I need it to be standards compliant XHTML so I don't want to use the deprecated 'name' attribute for <img>. Is that possible?

Thanks!

garann

8:20 pm on Aug 1, 2005 (gmt 0)

10+ Year Member



I don't write a lot of XHTML, but it should be possible. Does what's below work?


<script type="text/javascript">
var imgs = new Array("images/pic0.jpg","images/pic1.jpg");
function loadMainImg(num) {
document.getElementById("mainImg").src = imgs[num];
}
</script>
<img id="thumb0" onclick="loadMainImg(0)" src="thumbs/pic0.jpg"/>
<img id="thumb1" onclick="loadMainImg(1)" src="thumbs/pic1.jpg"/>
<img id="mainImg" src="images/somePic.jpg"/>