Click to See Complete Forum and Search --> : image swap problems in netscape and macs


wynton_ca
06-03-2003, 04:08 PM
Hey all, I was wondering if you might be able to help me with this one. This code works fine with IE on PC. However In Netscape 6x and on the mac (both browsers) the image does not change one bit. Ive put this together for an onclick event so that when the image is clicked, it will swap with another, and vice versa.

function chng(c_img, img1, img2) {
if (document[c_img].src.indexOf(img1)!= -1) document[c_img].src = img2;
else document[c_img].src = img1;
}

<a href="#" onclick="chng('show','firstimagepath.gif','secondimagepath.gif');"><img src="firstimage.gif" width="113" height="27" alt="Show Details" border="0" name="show"></a>

brendandonhue
06-03-2003, 04:53 PM
This works in netscape and its a slightly better method because in your code, you have to assign a name to each image. This will use "this" to get it automatically.

<script language="JavaScript">
function chng(c_img, img1, img2) {
if (c_img.src.indexOf(img1)!= -1) c_img.src = img2;
else c_img.src = img1;
}
</script>
<img src="fisrtimage.gif" width="113" height="27" alt="Show Details" border="0" onclick="chng(this,'firstimagepath.gif','secondimagepath.gif')">

<a href="#" onclick="chng('show','firstimagepath.gif','secondimagepath.gif');"><img src="firstimage.gif" width="113" height="27" alt="Show Details" border="0" name="show"></a>