Javascript Mouseover Problem

R

richk

For some reason when I add additional buttons a 3rd button and beyond
i cant get the effect to work and I get errors...I cant understand
why...

<SCRIPT LANGUAGE = "javascript"><!--

if (document.images) { // Active Images
img1on = new Image();
img1on.src = "button1_on.jpg";

img2on = new Image();
img2on.src = "button2_on.jpg";

img1off = new Image();
img1off.src = "button1_off.jpg";

img2off = new Image();
img2off.src = "button2_off.jpg"; }

// Function to 'activate' images.
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");
}
}

// Function to 'deactivate' images.
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");
}
}

// -->
</SCRIPT>


<A HREF="page1.htm" onMouseOver="imgOn('img1')"
onMouseOut="imgOff('img1')">
<IMG NAME="img1" SRC="button1_off.jpg" ALT="mouseover button"
HEIGHT="30"
WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>

<A HREF="page2.htm" onMouseOver="imgOn('img2')"
onMouseOut="imgOff('img2')">
<IMG NAME="img2" SRC="button2_off.jpg" ALT="another mouseover button"
HEIGHT="30"
WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
 
L

Lee

richk said:
For some reason when I add additional buttons a 3rd button and beyond
i cant get the effect to work and I get errors...I cant understand
why...

The code you posted only has 2 buttons (and there is
at least one typo). Post the code that you want to
work, but doesn't.
 
D

Dominique

I try with a third button and I don't see any problem
I use the following code and it seems to work

<html><head></head><body>
<SCRIPT LANGUAGE = "javascript"><!--

if (document.images) { // Active Images
img1on = new Image();
img1on.src = "button1_on.jpg";

img2on = new Image();
img2on.src = "button2_on.jpg";

img3on = new Image();
img3on.src = "button3_on.jpg";

img1off = new Image();
img1off.src = "button1_off.jpg";

img2off = new Image();
img2off.src = "button2_off.jpg";

img3off = new Image();
img3off.src = "button3_off.jpg";

}

// Function to 'activate' images.
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");
}
}

// Function to 'deactivate' images.
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");
}
}

// -->
</SCRIPT>


<A HREF="page1.htm" onMouseOver="imgOn('img1')"
onMouseOut="imgOff('img1')">
<IMG NAME="img1" SRC="button1_off.jpg" ALT="mouseover button"
HEIGHT="30"
WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
<br>
<A HREF="page2.htm" onMouseOver="imgOn('img2')"
onMouseOut="imgOff('img2')">
<IMG NAME="img2" SRC="button2_off.jpg" ALT="second mouseover button"
HEIGHT="30"
WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
<br>
<A HREF="page3.htm" onMouseOver="imgOn('img3')"
onMouseOut="imgOff('img3')">
<IMG NAME="img3" SRC="button3_off.jpg" ALT="third mouseover button"
HEIGHT="30"
WIDTH="147" VSPACE="0" HSPACE="0" BORDER="0"></A>
</body></html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top