Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

easy question: one click switch img, another click switch back

Status
Not open for further replies.

pb8185

Technical User
Jan 1, 2004
6
US
onMouseclick only works one way, is there anyway to code it to switch back to original image on second click or do you have to use java? and if so what would the code look like? It seems to be an easy problem
 
Try this.
[tt]
<html>
<head>
<script language="javascript">
var idx=0;
var aimg=["a.jpg","b.gif"]; //etc
</script>
</head>
<body>
<img src="aimg[0]" alt="picture avail on request" onclick="idx=(idx+1)%2;src=aimg[idx];" />
</body>
</html>
[/tt]
- tsuji
 
Directly code the image file at src may help alleviate the loadtime problem.
[tt]
<img src="[red]a.jpg[/red]" alt="picture avail on request" onclick="idx=(idx+1)%2;src=aimg[idx];" />
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top