Image Rollover and OnClick


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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you post your code?
rajesh75Author Commented:

function BOGo(id) {

      switch (id)
                  {      case "car" :
                              flg = "car";
                        case "hotels" :
                              flg = "hotels";
                        case "vac" :
                              flg = "vac";
                        case "lastmin" :
                              flg = "lastmin";
      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>

isn't this easier?

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

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

Good shoud work (as far as I know), as its not really doing anything fancy :-)

*crosses fingers*

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.