can't preload an image

yaniv

Centurion
Joined
Apr 15, 2002
Messages
167
Location
israel
i use this code to chane the apperence of my imagebutton during mouse over:


Code:
<script language =javascript > 

window.onload = function() {

 var img1_mover = new Image();

 var img1_mout = new Image();



 img1_mover.src = 'menu/link1_.gif';

 img1_mout.src = 'menu/link1.gif';

}

</script>


and then


Code:
<TD width="90" height="17"><asp:imagebutton id="ImageButton3" runat="server" ImageUrl="~/menu/link1.gif" onmouseover='src = img1_mover.src' onmouseout='src=img1_mout.src'></asp:imagebutton></TD>



when i run the page i get the error massage:
" runtime error of microsoft jscript, 'img1_mover' is not declared", does some body have an idea how to solve it?
 
Try this

Code:
<script language="javascript">
 
var imgMOver = new Image();
var imgMOut = new Image();
 
imgMOver.src = "IMAGE TO LOAD ON MOUSE OVER";
imgMOut.src = "IMAGE TO LOAD ON MOUSE OUT";
function MouseOver()
{
   this.src = imgMOver;
}
 
function MouseOut()
{
   this.src = imgMOut;
}
 
</script>

And you change your event function in the <asp:imagebutton>.
N.B. : Don't remember if functions in javascript use "{}".
 
Back
Top