Click to See Complete Forum and Search --> : Rollover Function Broken


JJBean
07-05-2005, 02:46 PM
Hi All,

I have the following code that goes nutz when I load page. Error shows up at
Document.images[ImgNum].src = imgSrc

Heres the code:

<html>
<head><title></title>


<script language="JavaScript1.1" type="text/JavaScript">
<!--
*
function yaImgChange(imgNum,imgSrc)
{
document.images[imgNum].src = imgSrc;
}


*-->
</script>
<body>

<br><br><br>

<a href="javascript:nothingMuch();" onMouseOver="yaImgChange(11,'calendar.gif');" onMouseOut="yaImgChange(11,'Calender2.gif');"> <img src="calendar.gif"></a>

</body>
</html>


What am I doing wrong?

Thanks,

JJ

yh0p2
07-05-2005, 03:06 PM
javascript:nothingMuch(); whats this? is it #?

and i think u got 2 images mixed up... calendar2.gif and calendar.gif

Mr J
07-05-2005, 03:13 PM
Try the following



<html>
<head>
<title></title>

<script type="text/javascript">
<!--

function yaImgChange(imgName,imgSrc){
document.images[imgName].src = imgSrc
}

//-->
</script>
<body>

<br><br><br>

<a href="javascript:nothingMuch();" onMouseOver="yaImgChange('mypic','calendar.gif');" onMouseOut="yaImgChange('mypic','calendar2.gif');"> <img name="mypic" src="calendar.gif"></a>

</body>
</html>

JJBean
07-05-2005, 04:36 PM
Great Thanks. That worked. Now the question is what was wrong with mine?

JJ

Mr J
07-06-2005, 03:24 AM
The main thing was you hadn't given your image tag a name or id.
The second was that you were passing a number as an argument which would suggest you were wanting to change the ordinal numbered image tags src, which would be image tag number 12, of which you only have 1

Graham Luff
07-06-2005, 08:49 AM
I have a simple website devoted to my daughter's life and am just starting year 3.

Year 2 has a rollover function and this year I wanted to add a slideshow (courtesy of Mike Canonigo on javacript.com) but the rollover function does not work anymore.

Rather than copy the code onto here may I direct you to:
www.geocities.com/grahamluff/emma2.html (for year 2 - nearly all links have the rollover function) to view the source code
and
www.geocities.com/grahamluff/wemma3c.html (for year 3 - slideshow works but the index link and the June link no longer rollover).

I would be very grateful for any help anyone can give me.

By the way, the original rollover code was sent me by someone who then sent me to javascript.com's site for more scripts but I don't know whose code I am using. If you recognise it please tell me and I will make sure you get a mention.

Thank you
Graham
Epsom
UK

Mr J
07-06-2005, 12:27 PM
You have missed the 5 off this line

dec0linkon = new Image();

should be

dec05linkon = new Image();

Graham Luff
07-07-2005, 06:52 PM
Mr J, I cannot thank you enough.

The website is wonderful now.

Graham