[Javascript] image swap

Tim Lewis twlewis at softhome.net
Tue Jul 17 08:29:49 CDT 2007


Jef, I might be misunderstanding what you are trying to do, but do you
just want to change the image when the mouse is moved over it?  if so, try
this code.  I have attached the two images used in the code to this email.

Tim

<html><head>
<script language=JavaScript>
<!--
//
_____________________________________________________________________________
function ImageClick() {
alert ("Image was clicked");
}
//
_____________________________________________________________________________
-->
</script></head>
<title id=onetidTitle>Intranet - Datagate Tools Segment</title>
<body>
<form name="DatagateTools_Segment_File">
<img id=imgMyImage src="Scooby_color_16.jpg"
OnClick="ImageClick()"
OnMouseOver="imgMyImage.src='Scooby_color.jpg'"
OnMouseOut="imgMyImage.src='Scooby_color_16.jpg'">
</form>
</body></html>


> hi everyone,
>
> i am just starting to learn JavaScript and could really use some help. i
> am trying to do an image swap code with onmouseover. i am just copying and
> pasting the code out of a book but can't figure out what to change in
> order to get it to work. it is from the o'reilly JavaScript book. here is
> the code:
>
> <script type="text/javascript">
> function rollOver()
> {
> var images = document.getElementsByTagName("img");
> for(var i = 0; i < images.length; i++);
>     {
>     var image = images[i];
>     var rolloverURL = image.getAttribute("rollover");
>     if (rolloverURL) addRollover(image, rolloverURL);
>     }
> }
> </script>
> <script>
> if (window.addEventListener)
>     window.addEventListener("load", rollOver, false);
> else if (window.attachEvent)
>     window.attachEvent("onload", rollOver);
> </script>
>
> so the first part is the actual function and the second calls it right? my
> question is which parts need to be modified. i have tried entering url's
> and still get nothing. the latest error i get  is that the image has no
> properties. can someone help me out with this. i would really appreciate
> it. i was told JavaScript was fairly easy to learn, i think i was lied to.
>
> Jeff
>
>
> ---------------------------------
> Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's
> on, when. _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Scooby_color.jpg
Type: image/pjpeg
Size: 2733 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070717/ed43d2ee/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Scooby_color_16.JPG
Type: image/pjpeg
Size: 2217 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070717/ed43d2ee/attachment-0001.bin>


More information about the Javascript mailing list