Madhukar Krishna

Madhukar Krishna

  • 688
  • 1.4k
  • 292.2k

Javascript: Image change not working

Mar 15 2014 2:25 PM
The following code is not working. It doesn't show any image. Please help.
 
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var myVar = setInterval(function(){randim()},1000);
function randim(){
var bannerImages = new Array( );
bannerImages[0] = "1.jpg";
bannerImages[1] = "2.jpg";
bannerImages[2] = "3.jpg";
bannerImages[3] = "4.jpg";
bannerImages[4] = "5.jpg";
bannerImages[5] = "6.jpg";
bannerImages[6] = "7.jpg";
var randomImageIndex = 0;
randomImageIndex = Math.round( Math.random( ) * 6 );
}
function myStopFunction()
{
clearInterval(myVar);
}
</script>
<p>A script on this page starts this image change:</p>
<img src="\""+bannerImages[randomImageIndex]+"\"" />
<button onclick="myStopFunction()">Stop image</button>
</body>
</html>
 

Answers (2)