Click to See Complete Forum and Search --> : change an image by a click
pelegk1
12-14-2003, 03:35 AM
i have an imgage in html file
<img src="arow1.gif">
and i want to change it when a user clicks to
"arrow2.gif"
how do i do that?
thanks in advane
peleg
Pittimann
12-14-2003, 03:54 AM
Hi!
Try something like that:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function changeImage(){
document.toBeChanged.src="arrow2.gif";
}
//-->
</script>
</head>
<body>
<a href="#" onclick="javascript:changeImage()"><img src="arow1.gif" name="toBeChanged" border="0"></a>
</body>
</html>
Cheers - Pit
fredmv
12-14-2003, 01:22 PM
<img src="arrow1.gif" onclick="src='arrow2.gif';" alt="" />
Pittimann
12-14-2003, 02:02 PM
Hi!
I know, I'm not only some sort of conservative, but also outdated. Anyway - in my "beloved" NS 4.x (and other outdated browsers)
<img src="arrow1.gif" onclick="src='arrow2.gif';" alt="" />
doesn't work :(. Because of that, I suggested the huge snippet...
Cheers - Pit
fredmv
12-14-2003, 02:11 PM
This would provide functionality in Netscape 4.x:<a href="#" onclick="document.images['foo'].src='arrow2.gif';"><img src="arrow1.gif" name="foo" alt="" /></a>
Pittimann
12-14-2003, 02:17 PM
You're a champ! ;)
Cheers - Pit
fredmv
12-14-2003, 02:20 PM
Thanks. I see where you're coming from on making things functional in Netscape 4.x (and other extremely old browsers), however, something that simple (as in my previous code) should've worked correctly, although I'm sure there's a good reason why it didn't. :D
Pittimann
12-14-2003, 02:31 PM
Hi!
You're absolutely right! The good reason is the user (in this case - even if I'm not an NS user: me!).
Sorry I am extremely old - but I can live with that...
Cheers - :pit