Change between 2 images

Hello,

Im tray to do some script that change between 2 images:

I want to show one image that eich click chage it.

When i click on the image it change to img1 and when i click again it chage to img2.

Change btween img1 to img2 and img2 to img1…

How i can do it?

Thank you very much!!

Hi there taly88,

and a warm welcome to these forums. :wink:

Here is a basic example…

[color=navy]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<base href="http://www.coothead.co.uk/images/">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
body {
    background-color:#c0c0c0;
 }
#myimage {
    display:block;
    width:360px;
    height:280px;
    border:3px double #000;
    margin:auto;
    cursor:pointer;
 }
</style>

<script type="text/javascript">

function swapImage(){
   test=true;
   obj=document.getElementById('myimage');
obj.onclick=function() {
   test=(test==true)?
   (obj.src='banana.jpg',test=false):
   (obj.src='apple.jpg',test=true);
  }
 }

if(window.addEventListener){
   window.addEventListener('load',swapImage,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',swapImage);
  }
 }
</script>

</head>
<body>

<div>
 <img id="myimage" src="apple.jpg" alt="apple">
</div>

</body>
</html>
[/color]

coothead

Thanks coothead!!

But do you have some solution for me to do it with out javascript?

I’m tray to add this code to post in wordpress but its not get java only php/html.

Hi there taly88,

you posted your problem in the JavaScript forum.

If you do not want a javascript solution then you should post your problem in the forum appropriate to your requirements. :wink:

coothead

Ok i will do it right now…

Sorry about this, i see only now that i cant add only PHP/HTML code…

The thread is continued here.