Need help with onmouseclick

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have this code below to do a rollover image.  IT doesnt work with the
onmouseclick event. But it wil lwork fine with the onmouseover so when the
user hovers over the image, the main image changes.  I am trying to do an
onmouseclick event so when the user clicks on the link, it will change the
main image,  but it doesnt work.  What can I do?

<img name="rollover" src="/images/image1.jpg" border=0  width="200"
height="300" >

 <a href onmouseclick='rollover.src = "/images/image2.jpg"'
onmouseout='rollover.src="/images/image1.jpg"'> <img
src="/images/image2.jpg" border=0 width=75 height=100></a>

Re: Need help with onmouseclick

> I have this code below to do a rollover image.  IT doesnt work with the  
> onmouseclick event.

That's because there's no such intrinsic event: it's click (onclick as an  


> <img name="rollover"

Unless you actively care about old browsers, id the image

   <img id="rollover" ...>

> src="/images/image1.jpg" border=0

The border attribute is deprecated. Use CSS to style documents.


>  <a href

The appropriate URL here would be the image. This would mean that visitors  
that don't have scripting enabled can navigate to, and see, your image.

> onmouseclick='rollover.src = "/images/image2.jpg"'

Relying the user agent's ability to resolve name or id values as global  
variables is risky, and will frequently fail. To access an IMG element,  
use the images collection:

   document.images['imageName-or-Id'].src = '...';

You'll also need to cancel the click event. If you don't, the browser will  
continue to request the linked resource after the script has executed. You  
do that by returning false from the event listener.

   <a href="/images/image2.jpg"
    onclick="changeImg(this.href); return false;">

where changeImg is

   function changeImg(url) {
     document.images['rollover'].src = url;

> <img src="/images/image2.jpg" border=0 width=75 height=100></a>

Both here, and earlier, you have omitted the alt attribute on the IMG  
element. Don't.

Hope that helps,

Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.

Site Timeline