...

View Full Version : image swaping



gablernyc
07-15-2003, 09: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.

Mhtml
07-15-2003, 09: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.

gablernyc
07-15-2003, 10: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.

cheesebagpipe
07-16-2003, 12:30 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript">

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

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

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

I owe you one.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum