Click to See Complete Forum and Search --> : dhtml, html, or javascript??


dennic
02-12-2003, 01:16 AM
Hey

i building my own website and am just curious about something. when someone clicks on an image("image1.gif") i want the image to change into a different image("image2.gif")
how do i get this function to work properly??

AdamGundry
02-12-2003, 03:48 AM
Try this (though you might want to preload image2.gif):

<img src="image1.gif" onclick="this.src = 'image2.gif'">


Adam

gmichal
03-07-2003, 01:48 PM
what the syntax for the preload img? i know u need to write it on the body tag
<body onload="?????">

AdamGundry
03-09-2003, 02:31 PM
Use something like this:

<body onload="preloadImages()">

<script type="text/javascript">
var i = new Image();
i.src = 'image2.gif';
</script>


This creates a new image object and assigns it at source of image2.gif, so when the browser finishes loading (the onLoad event is called) the image will be preloaded for the change.

Adam