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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onmouseovers with background images 1

Status
Not open for further replies.

danima

Programmer
Jan 9, 2002
134
CA
I'm looking for code to make background images in a <TD> change with a mouseover. Currently I use the following code for a mouseover effect for graphics:

<a href=&quot;&quot;
onmouseover=&quot;move_it('menu4','images/right_menu4b.gif')&quot;
onmouseout=&quot;move_it('menu4','images/right_menu4.gif')&quot;>

But this time I want to use simple text (because we'll probably change these often) and only have the background change....leaving the text in the <TD>

Any help would be much appreciated!
 
Try the code below;

<HTML>
<HEAD>
<Script language=&quot;JavaScript1.3&quot;>
function ChangeBackGroundImage(pTDid,pImageName){
var objTD=document.getElementById(pTDid);

var sPath=&quot;images/&quot;+pImageName;
objTD.style.backgroundImage = &quot;url(&quot;+sPath+&quot;)&quot;;
}
</Script>
</HEAD>
<BODY>
<TABLE >
<TR ><TD id=Row1Col1 onmouseover='ChangeBackGroundImage(&quot;Row1Col1&quot;,&quot;YourImageName&quot;)'

onmouseout='ChangeBackGroundImage(&quot;Row1Col1&quot;,&quot;YourImageName&quot;)'>Some Text Inside</TD></TR>
</TABLE>
</BODY>
</HTML> &quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Works perfect. Thanks. One thing....the mouseover and mouseout work...but the <TD> is blank until I mouseover it. When I mouseout the image is there...but if I refresh the page it's just white? How would I get the image to appear from the onset?

I tried background=&quot;/image/myimage.gif&quot; in the TD...but that didn't do it?

Thanks again for the help!!!
 
<TR ><TD id=Row1Col1 style=&quot;background-image:'url(images/YourStartImage.jpg)'&quot;

onmouseover='ChangeBackGroundImage(&quot;Row1Col1&quot;,&quot;button1.jpg&quot;)'

onmouseout='ChangeBackGroundImage(&quot;Row1Col1&quot;,&quot;button2.jpg&quot;)'>Some Text Inside</TD></TR> &quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Yes sir!!!! Worked like a charm. Thanks a million!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top