Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to put your code inside <code>window.onload = function() {}</code></p> <pre><code>var images = new Array(); images[0] = "img2.gif"; images[1] = "img3.gif"; images[2] = "img4.gif"; images[3] = "img5.gif"; images[4] = "img6.gif"; images[5] = "img7.gif"; images[6] = "img8.gif"; images[7] = "img9.gif"; images[8] = "img10.gif"; function changeImage() { document.getElementById('ad').src = images[x]; if (x&lt;8) { x+=1; } else if (x===9) { x=0; } } window.onload = function() { var x = 0; setInterval(function() { changeImage() },5000); } </code></pre> <h1>Edit</h1> <p>This code has been tested on my local machine and works.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var images = new Array(); for (var i = 2; i &lt; 11; i++) { images.push("img" + i + ".gif"); } var x = 0; function changeImage() { document.getElementById('ad').src = images[x]; document.getElementById('imgsrc').innerHTML = "&lt;h1&gt;" + images[x] + "&lt;/h1&gt;"; if (x &lt; 8) { x += 1; } else { x = 0; } } window.onload = function() { setInterval(function () { changeImage(); }, 1000); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img id="ad" src="img.gif" /&gt; &lt;div id="imgsrc"&gt;&lt;h1&gt;img.gif&lt;/h1&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><a href="http://jsfiddle.net/nwsjE/3/" rel="nofollow">Here</a> is a fiddle of the final code working. JSFiddle doesn't like <code>window.onload</code> for some reason, so I had to exclude it. This doesn't really demonstrate my point, but I thought I'd just include it anyway.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload