Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

click on one image to change another

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
I have a a small collection of images that I want to display on my webpage, the thing is I want to be able to click on an image (.i.e the trigger) that changes the image (i.e the target). And everytime you click on the trigger image it changes the target image to a different one. I was wondering exactly how I would implement this in javascript? A small example would be very grateful.

Taval
 
something like this should work:

<script>
arraySrc = new Array();
arraySrc[0] = &quot;unf.gif&quot;;
arraySrc[1] = &quot;fut.gif&quot;;
var x = 0;
function change(target)
{
if(x >= arraySrc.length)
{
x = 0;
}
document.images[target].src = arraySrc[x];
x++;
}
</script>

<img onclick=&quot;change('ben')&quot;>
<img name=&quot;ben&quot;>
adam@aauser.com
 
Thanks for that, I'll try that out.

Taval
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top