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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing image when clicked 2

Status
Not open for further replies.

fxcolin

Technical User
Oct 14, 2001
169
0
0
CA
hi there,

I hope someone can help with this.

I have an image gallery where each picture changes to a coloured version on hover. How would I get the coloured version to appear and stay there when each image is clicked.

onclick or OnMouseClick ?
I've tried and can't get it.

Here's a piece of code:
<a href=&quot;javascript:popImage('pics/teaching.jpg','Teaching Cooks');&quot; onMouseOver=&quot;MM_swapImage('A01','','pics/teaching_colour.jpg',1)&quot; onMouseOut=&quot;MM_swapImgRestore()&quot;><img src=&quot;pics/teaching_black.jpg&quot; name=&quot;A01&quot; width=&quot;49&quot; height=&quot;29&quot; border=&quot;0&quot; id=&quot;A01&quot;></a>

Here's the page it's Currently on
Thanks

Today's Quote:
&quot; Psycho-Therapy is expensive...
but, bubble wrap is cheap. You choose &quot;

Hosting for: Web Designers & Resellers
]|
 

Add
Code:
onclick=&quot;this.onmouseout='return false';&quot;
inside the image tag.

 
I'm thinking you can add an toggle onClick event and set a
variable to be read by the onMouseOut=&quot;MM_swapImgRestore()
like:

declare a global variable
<script>
var swap = true;

function MM_swapImgRestore() {
if(swap) {
.... all your current code ....
}
else { swap = true; }
}

then with your onClick you can set the swap variable

<a ... ... ... onClick=&quot;swap=false;&quot;>

2b||!2b
 
yup, try this:
<img src=&quot;...&quot; onclick=&quot;this.src='old image path'&quot; onmouseover=&quot;this.src='new image path'&quot;>

Known is handfull, Unknown is worldfull
 
theboyhope,

Very efficient!*
Last I checked fxcolin was using your solution.

2b||!2b
 
Yes, thanks to all of you that responded.

I did start with theboyhope's solution.
At first it didn't work in the image tag, so I moved it into the href tag and voila ! Sweet !

Thanks theboyhope. You get a star from me also !

Today's Quote:
&quot; Psycho-Therapy is expensive...
but, bubble wrap is cheap. You choose &quot;

Hosting for: Web Designers & Resellers
]|
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top