topical media & game development

talk show tell print

basic-javascript-05-ch5-examp5.htm / htm



  <html>
  <head>
  <script language="JavaScript" type="text/javascript">
  var myImages = new Array("usa.gif","canada.gif","jamaica.gif","mexico.gif");
  function changeImg(imgNumber)
  {
     var imgClicked = document.images[imgNumber];
     var newImgNumber = Math.round(Math.random() * 3);
     while (imgClicked.src.indexOf(myImages[newImgNumber]) != -1)
     {
        newImgNumber = Math.round(Math.random() * 3);
     }
     imgClicked.src = myImages[newImgNumber];
     return false;
  }
  </script>
  </head>
  <body>
          <img name="img0" src="usa.gif" border="0" onclick="return changeImg(0)">
          <img name="img1" src="mexico.gif" border="0" onclick="return changeImg(1)">
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.