Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing an image when "on MouseOver"

Status
Not open for further replies.

jlawler

Programmer
Feb 26, 2003
14
IE
Hi,

Why wont the following code work? I want to change the image when the mouse is moved it.

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>

function changeImage(imgName, newSrc) {
imgName.src = newSrc;
}

</script>

<a href=&quot;/../fund/fund.html&quot; onmouseover=&quot;changeImage('getquote','../images/getquoteR.gif');&quot; onmouseout=&quot;changeImage('getquote','../images/getquote.gif');&quot;><img src=&quot;../images/getquote.gif&quot; name=&quot;getquote&quot; width=&quot;142&quot; height=&quot;36&quot; border=&quot;0&quot; ></a>

The image is appearing but wont change when I move the mouse over. The changeImage function is being called and the parameters are being passed correctly, but the image wont change.

There has to be an easy answer, any help appreciated
Thanks
jlawler

 
this is a bit bulky ... but it works so well, and is VERY hard to mess up.


(in head)

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- begin hiding script


if (document.images)
{

name1on = new Image(133, 20);
name1on.src = &quot;image/home_o.gif&quot;;
name2on = new Image(133, 20);
name2on.src = &quot;image/hist_o.gif&quot;;
name3on = new Image(133, 20);
name3on.src = &quot;image/kid_o.gif&quot;;
name4on = new Image(133, 20);



name1off = new Image(133, 20);
name1off.src = &quot;image/home.gif&quot;;
name2off = new Image(133, 20);
name2off.src = &quot;image/hist.gif&quot;;
name3off = new Image(133, 20);
name3off.src = &quot;image/kid.gif&quot;;


}

function img_act(imgName)
{
if (document.images)
{
imgOn = eval(imgName + &quot;on.src&quot;);
document
.src = imgOn;
}
}

function img_inact(imgName)
{
if (document.images)
{
imgOff = eval(imgName + &quot;off.src&quot;);
document
.src = imgOff;
}
}


// end script hiding-->

</SCRIPT>



(for mouseovers ...)

<a href=&quot;link if needed&quot; onMouseover = &quot;img_act('name1')&quot; onMouseout = &quot;img_inact('name1')&quot;><img src=&quot;image/home.gif&quot; name=&quot;name1&quot; width=&quot;241&quot; height=&quot;24&quot; alt=&quot;&quot; border=&quot;0&quot;></a>

<a href=&quot;link if needed&quot; onMouseover = &quot;img_act('name2')&quot; onMouseout = &quot;img_inact('name2')&quot;><img src=&quot;image/kid.gif&quot; name=&quot;name2&quot; width=&quot;241&quot; height=&quot;24&quot; alt=&quot;&quot; border=&quot;0&quot;></a>

<a href=&quot;link if needed&quot; onMouseover = &quot;img_act('name3')&quot; onMouseout = &quot;img_inact('name3')&quot;><img src=&quot;image/hist.gif&quot; name=&quot;name3&quot; width=&quot;241&quot; height=&quot;24&quot; alt=&quot;&quot; border=&quot;0&quot;></a>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top