title: Use javascript to set a random image
body: <p>I am relatively new with javascript and as such, my code to get a random image to show up when my page loads is not working. I have looked at a few examples to try and solve the problem, but after a few hours of searching I am ready to press the help button. I have included the HTML and script for my page. Additionally, I have commented the IMG tag I am trying to manipulate.</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Welcome in.&lt;/title&gt;
  &lt;link href="home.css" rel="stylesheet" type="text/css" media="screen" /&gt;
  &lt;script type="text/javascript" src="jquery-1.7.1.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="slides.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  //This is where I am attempting to set an random image to load.
  function()
  {   
      //Array of quotes
      var randomImages= new Array ("Images/quote1.png", "Images/quote2.png","Images/quote3.png", "Images/quote4.png", "Images/quote5.png","Images/quote6.png","Images/quote7.png","Images/quote8.png");
  
      //Random number to select an image. Use 8, not 7, since javascript arrays are 0 based
      //Math.floor will take us from a floating point number to an integer base
      var randomNumber = Math.floor(7*Math.random());
  
  
      //Display that image
      document.getElementById('quoter').setAttribute('src',randomImages[randomNumber]);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onLoad="function()"&gt;
  &lt;a href="aboutme.html" id="aboutMe"&gt;&lt;img src="Images/aboutme.png" alt="aboutme"/&gt;&lt;/a&gt;
  &lt;a href="aboutme.html" id="contact"&gt;&lt;img src="Images/contact.png" alt="aboutme"/&gt;&lt;/a&gt;
  &lt;a href="aboutme.html" id="blog"&gt;&lt;img src="Images/blog.png" alt="aboutme"/&gt;&lt;/a&gt;
  &lt;a href="aboutme.html" id="wife"&gt;&lt;img src="Images/mywife.png" alt="aboutme"/&gt;&lt;/a&gt;
  &lt;div id="mid"&gt;
  &lt;/div&gt;
  &lt;div id="slideshow"&gt;
     &lt;div&gt;
       &lt;img src="Images/dummypic.png" alt="me"&gt;
     &lt;/div&gt;
     &lt;div&gt;
       &lt;img src="Images/dummypic2.png" alt="me"&gt;
     &lt;/div&gt;
     &lt;div&gt;
       &lt;img src="Images/dummypic3.png" alt="me"&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  &lt;div&gt;
  &lt;img id="quoter" src="" alt="quotes"&gt; &lt;!--This is what I am trying to make random when the page loads--&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>