View Full Version : image swaping

07-15-2003, 10:51 PM
I am having some trouble with an image click. I am trying to change the image when the user clicks it, but then revert back to the original image when the new image is clicked.

Basically its an open and close button. The area is open when the screen loads, and closes when the user clicks the button. We need to have the open close button change when the user does this.

As always thanks in advance for any help.

07-15-2003, 10:56 PM
Well, where's your code?

It should be something like this -

<img src="yourimage.gif" onclick="if(this.src=='yourimage.gif'){this.src='yourotherimage.gif'}else{this.src='yourimage.gif'}">

Probably not an idea to do lots of buttons like that but rather to have a function, but if you only have one buton that's acceptable I think.

07-15-2003, 11:21 PM
<a href="#" onClick="toggle('therow'); return false"><img src="../common/images/minus_open.gif" width="20" height="16" border="0" align="absmiddle"></a>

the toggle functionality is in a script.

I tried adding your code snippet, but nothing happens. the image doesnt swap out.

07-16-2003, 01:30 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

<script type="text/javascript">

$ = new Image();
$.src = 'http://www.codingforums.com/images/reply.gif';
$$ = 'http://www.codingforums.com/images/newthread.gif';

<img src="http://www.codingforums.com/images/newthread.gif" onclick="this.src=(this.latched)?$$:$.src;this.latched=!this.latched">

07-16-2003, 03:25 PM
Thank you very much. this worked and did the trick.

I owe you one.