PDA

View Full Version : define an imageSwap function


Beck1
08-29-2002, 11:00 AM
Can someone tell me how I can define an imageSwap function in the HEAD area please? - So that I can call up the function for rollover graphics.

Thanks very much,
Beck

requestcode
08-29-2002, 01:25 PM
Maybe this example will help:
<html>
<head>
<title>Multi Image Flip</title>
<SCRIPT LANGUAGE="JavaScript">
function swap(image,imgname)
{
eval("document."+imgname+".src=image")
}
</SCRIPT>
</head>
<body>
<CENTER>
<BR>
<BR>
<A HREF="page.html" onMouseOver="swap('0.gif','img1')" onMouseOut="swap('1.gif','img1')"><IMG SRC="1.gif" NAME="img1" BORDER="0"></A><br>
<A HREF="page.html" onMouseOver="swap('3.gif','img2')" onMouseOut="swap('2.gif','img2')"><IMG SRC="2.gif" NAME="img2" BORDER="0"></A><br>
</body>
</html>

When someone mouses over or out of an image the function swap is performed. The name of the image to swap to and the name of the image tag are also passed to the function. This is so that the function can be used by multiple image swaps.