unplugged_web Posted October 31, 2007 Share Posted October 31, 2007 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()"> Link to comment Share on other sites More sharing options...
Reg Edit Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
Synook Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
unplugged_web Posted November 1, 2007 Author Share Posted November 1, 2007 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')" /> Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.