PDA

View Full Version : I'm new, please help. Why does one work and not the other?



Mar
10-24-2004, 05:00 PM
I have what I think is the exact same code. I just changed the name of an image. And even when I make the names the same, one works and the other does not. Can anyone see what the problem is?

Here is the code I have:
if (document.images)
{
image_off= new Image(100, 100);
image_off.src= "waterfall.jpg";

image2= new Image(100,100);
image2.src="dinoa.jpg";
image3= new Image(100,100);
image3.src="tornato1.jpg";
image4= new Image(100,100);
image4.src="moons.jpg";
image5= new Image(100,100);
image5.src="dolphin1.jpg";
image6= new Image()100,100);
image6.src="deepsea.jpg";
}

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

</head>
<body >
<p><h2><center>
Some Things That Interest Me Are:</center></h2></p>

<p><center>
<a href="http://www.ucmp.berkeley.edu/diapsids/dinosaur.html" onMouseover="change1('waterfall','image2')" onMouseout="change1('waterfall','image_off')">Dinosaurs</a>
&nbsp;&nbsp;
<a href="http://www.okstate.edu/aesp/image.html" onMouseover="change1('waterfall','image3')" onMouseout="change1('waterfall','image_off')">Tornatos</a>
&nbsp;&nbsp;
<a href="http://www.photolib.noaa.gov/nssl/" onMouseover="change1('waterfall','image4')" onMouseout="change1('waterfall','image_off')">Space</a>
&nbsp;&nbsp;
<a href="http://www.southwest.com.au/~kirbyhs/dolphins.html" onMouseover="change1('waterfall','image5')" onMouseout="change1('waterfall','image_off')">Dolphins</a>
&nbsp;&nbsp;
<a href="http://www.divers-den.com/" onMouseover="change1('waterfall','image6')" onMouseout="change1('waterfall','image_off')">Deep Sea Animals</a>
</center></p><br/><br/><br/>
<p><center>
<img src="waterfall.jpg" name="waterfall" width="100" height="100" alt="waterfall" border="0"><br/>


Here is the other script:

if (document.images)
{
image_off= new Image(100,100);
image_off.src="waterfall.jpg";

image2= new Image(100,100);
image2.src="dinoa.jpg";
image3= new Image(100,100);
image3.src="tornato1.jpg";
image4= new Image(100,100);
image4.src="moons.jpg";
image5= new Image(100,100);
image5.src="deepsea.jpg";
image6= new Image(100,100);
image6.src="dolphin1.gif";
}

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






</head>
<body>
<p><h2><center>
Some Things That Interest Me Are:</center></h2></p>

<p><center>
<A HREF="http://www.ucmp.berkeley.edu/diapsids/dinosaur.html" onMouseover="change1('pic1','image2')" onMouseout="change1('pic1','image_off')">Dinosaurs</A>
&nbsp;&nbsp;
<A HREF="http://www.okstate.edu/aesp/image.html" onMouseover="change1('pic1','image3')" onMouseout="change1('pic1','image_off')">Tornatos</A>
&nbsp;&nbsp;
<A HREF="http://www.photolib.noaa.gov/nssl/" onMouseover="change1('pic1','image4')" onMouseout="change1('pic1','image_off')">Space</A>
&nbsp;&nbsp;
<A HREF="http://www.divers-den.com/" onMouseover="change1('pic1','image5')" onMouseout="change1('pic1','image_off')">Deep Sea Animals</A>
&nbsp;&nbsp;
<A HREF="http://www.southwest.com.au/~kirbyhs/dolphins.html" onMouseover="change1('pic1','image6')" onMouseout="change1('pic1','image_off')">Dolphins</A>
</center></p><br/><br/><br/>
<p><center>
<IMG SRC="waterfall.jpg" name="pic1" width="100" height="100" border="0">
</center></p>

Any idea's?

Thank you in advance.

Mar
10-24-2004, 09:46 PM
I found the problem. I had () in image 6