Problems with Javascript

They have: 3 posts

Joined: Sep 2002

Greetings, i have been working over my personal site and i decided to add to it that nifty Javascript trick where you hover the mouse over a link and an image is changed (you know, you have a nav. bar and above is an image which shows a description). I tried first with a simpel turn on/off script and it worked fine. However, now that there is more than one image to show, the script gets a syntax error. The code is the following:

Head:

  if (document.images)
   {
     pic_off= new Image(162,166);
     pic_off.src="menudisplayoff.jpg"; 

     pic2= new Image(162,166);
     pic2.src="menudisplay2.jpg";
     pic3= new Image(162,166);
     pic3.src="menudisplay3.jpg";
     pic4= new Image(162,166);
     pic4.src="menudisplay4.jpg";
     pic5= new Image(162,166);
     pic5.src="menudisplay5.jpg";
   }

function change1(picName,imgName)
{
   if (document.images)
    {
      imgOn=eval(imgName + ".src");
      document[picName].src= imgOn;
    }
}
'

Body:

<A HREF="index.html" onMouseover="change1('pic1','image2')" onMouseout="change1('pic1','image_off')">Click here</a>
&nbsp;&nbsp;
<A HREF="index.html" onMouseover="change1('pic1','image3')" onMouseout="change1('pic1','image_off')">Click here</a>
&nbsp;&nbsp;
<A HREF="index.html" onMouseover="change1('pic1','image4')" onMouseout="change1('pic1','image_off')">Click here</a>
&nbsp;&nbsp;
<A HREF="index.html" onMouseover="change1('pic1','image5')" onMouseout="change1('pic1','image_off')">Click here</a>
&nbsp;&nbsp;
<IMG SRC="menudisplayoff.jpg" name='pic1' border="0">
'

If you want to see a 'prevew' to the site, go to http://www.eracreations.com/members/leviathan/pages/temple

and enter to the page where i have the error.

EDIT: whoops, wrong forum section. Apologizes for that.

He has: 296 posts

Joined: May 2002

Hey Levi!

shouldn't 'onMouseout="change1('pic1','image_off')"' be 'onMouseout="change1('pic1','pic_off')"'?

They have: 3 posts

Joined: Sep 2002

Hello Necro!

Well, it seems you are right, it was supposed to be 'image' instead of 'pic', but apparently i ddint saved my .js. Heheh, it works now. Thanks for noticing it.

They have: 15 posts

Joined: Jun 2002

You never saved you .js? 0.o

He has: 296 posts

Joined: May 2002

Heh, gotta love simple mistakes like that Smiling

They have: 3 posts

Joined: Sep 2002

Blek, yeah. Punch me =P

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.