• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

Image Rollover and OnClick

Hi,

I have this onClick and mouseover script for a set of images with a "on" and "off" state.

The problem I have is that although the onClick works and it changes the image's "off" state to "on", I always need to right click and click "Show Picture" to make the image visible.

Why would this happen?

I am using "eval" to dynamically find the image and change the src.

Thanks for any help in advance.
0
rajesh75
Asked:
rajesh75
  • 4
  • 3
1 Solution
 
TimYatesCommented:
Can you post your code?
0
 
rajesh75Author Commented:
Javascript:


function BOGo(id) {

      switch (id)
                  {      case "car" :
                              flg = "car";
                              break;
                        case "hotels" :
                              flg = "hotels";
                              break;
                        case "vac" :
                              flg = "vac";
                              break;
                        case "lastmin" :
                              flg = "lastmin";
                              break;
                                          }
                  
      eval("document." + flg + ".src = \"./Images/admod_" + flg + "_on.gif\"");
}

Calling function:

<A onclick="BOGo('vac');" href="javascript:void(0);"><Img src="./Images/admod_vac_off.gif" border="0" name="vac" border=0>

Thanks.
0
 
TimYatesCommented:
isn't this easier?

    function BOGo( tImg )
    {
         tImg.src = './Images/admod_' + tImg.id + '_on.gif' ;
    }

    <img src="Images/admod_vac_off.gif" border="0" id="vac" border="0" onclick="BOGo( this )">

Tim
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
rajesh75Author Commented:
Thanks Tim. This is a cross browser script right? Would this work on some of the older versions of Netscape and IE?

Thanks again.
0
 
TimYatesCommented:
as far as I know...  I've not been doing javascript long though...  so I may be wrong :-/
0
 
rajesh75Author Commented:
I'd like to test this script on a few older browsers and if everything goes well, you got the points !

Thanks.
0
 
TimYatesCommented:
Good luck..it shoud work (as far as I know), as its not really doing anything fancy :-)

*crosses fingers*

Tim
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now