1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Image Swap

Discussion in 'JavaScript' started by annbee, Mar 22, 2011.

  1. #1
    on click link...can anyone help me to do this by hand code..its been ages since I've done it..no dreamweaver please...no swf..either :) thanks
     
    annbee, Mar 22, 2011 IP
  2. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Here is one example:

     
    Jan Novak, Mar 23, 2011 IP
  3. wsrinivas

    wsrinivas Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    a simple swap script like above should do the job
     
    wsrinivas, Mar 23, 2011 IP
  4. annbee

    annbee Member

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #4
    thank you..but what if i need to have both images point to a link..the same link?
     
    annbee, Mar 23, 2011 IP
  5. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #5
    If I understand it correctly, you need this:

    
    <html>
      <head>
        <title>Set Image Test
        </title>
    <script type="text/javascript">
    window.onload=function(){
      img1 = new Image ();
      img1.src = "Image1.jpg";
      img2 = new Image ();
      img2.src = "Image2.gif";
      img3 = new Image ();
      img3.src = "Image3.jpg";
    }
    function setImage (obj1, obj2)
    {
      var image = document.getElementById ("myimg");
      if(image.src == obj1.src){
        image.src = obj2.src;
      }else{
        image.src = obj1.src;
      }
    }
    </script>
      </head>
      <body>
        <a href="javascript:setImage (img1 , img2)">  
          <img id="myimg" alt="My Image" src="Image1.jpg" /></a>
      </body>
    </html> 
    
    Code (markup):
     
    Jan Novak, Mar 23, 2011 IP