views:

45

answers:

2

I confess, I'm a javascript noob. Part one of my current task is I'm trying to get a .png file to be replaced with another .png when the user mouses over the upper left corner of the first .png. When he mouses off, the .png needs to revert back to the initial .png file.

I'm trying to use an image map and java script to accomplish this. I am getting the following error on line 17:

'StaticImage1 is undefined"

Line 17 is the "area coords=..." line below:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Hot Spot Test</title>
<script language="javascript" type="script">
loadImageUL = new Image();
loadImageUL.src = "images/image2.png";
staticImage1 = new Image();
staticImage1.src = "images/image2.png";
</script>
</head>
<body>
    <p>
    <map id="FPMap1" name="FPMap1">
        <area coords="0, 0, 111, 96" href="http://thepcparamedics.com/" shape="rect"  onmouseover="image1.src=loadImageUL.src;" onmouseout="image1.src=staticImage1.src;" />
    </map>
    <img name="image1" alt="" height="203" src="images/image1.png" width="234" usemap="#FPMap1" />
</p>
</body>

I know I must be missing something simple. Thanks in advance for your assistance.

Mike

+1  A: 

Your script type should be text/javascript, and you can leave out the language

K Prime
A: 

OK. So there were a few issues with the code unrelated to the problem. Such as StaticImageUL and StaticImage2 both being assinged image2.png.

That being said, the cause of the error was due to the Type="script" in the script element. I changed this to type="" and the code seems to work as desired.

Mike Wittmer