Jump to content

Image swap/restore.....


unplugged_web

Recommended Posts

I have a simple image that is changed to another image when somebody clicks on it. I want the original image to be restored when they click again. I've used
 <img src=".images/tc.gif" id="Image1" onClick="MM_swapImage('Image1','','/images/tc_active.gif',1)" onClick="MM_swapImgRestore()">

You can't put two onclick attributes! Unless you have one of those MM_ functions that handles the toggling itself, you'll have to create a little function that checks what the image currently is, and sets it to the other image. You would then put your new function as the onclick attribute value.
Link to comment
Share on other sites

E.g.

<script>	function swapImage(target, old, new) {		if (target.src == old) {			target.src = new;		} else {			target.src = old;		}</script><img src="old_image.gif" onclick="swapImage(this, 'old_image.gif', 'new_image.gif')" />

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...