Problems with Javascript
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>
<A HREF="index.html" onMouseover="change1('pic1','image3')" onMouseout="change1('pic1','image_off')">Click here</a>
<A HREF="index.html" onMouseover="change1('pic1','image4')" onMouseout="change1('pic1','image_off')">Click here</a>
<A HREF="index.html" onMouseover="change1('pic1','image5')" onMouseout="change1('pic1','image_off')">Click here</a>
<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.
necrotic posted this at 01:13 — 26th September 2002.
He has: 296 posts
Joined: May 2002
Hey Levi!
shouldn't 'onMouseout="change1('pic1','image_off')"' be 'onMouseout="change1('pic1','pic_off')"'?
Alevice posted this at 01:23 — 26th September 2002.
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.
BboyEra posted this at 01:23 — 26th September 2002.
They have: 15 posts
Joined: Jun 2002
You never saved you .js? 0.o
necrotic posted this at 01:24 — 26th September 2002.
He has: 296 posts
Joined: May 2002
Heh, gotta love simple mistakes like that
Alevice posted this at 01:25 — 26th September 2002.
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.