title: How would I refresh just a portion of JavaScript code and not the entire page?
body: <p>I am trying to figure out how I can get just this code to refresh without the whole page refreshing. </p>
  
  <p>Here is how it works.</p>
  
  <ol>
  <li>Page is opened.</li>
  <li>User is prompted to pick blue, green, or red.</li>
  <li>Code looks at date, and then determines the hour.</li>
  <li>Code is used to pick an image that represents the first digit of the hour. It also chooses the correct color of the image.</li>
  </ol>
  
  <p>I'd like this code to refresh and display a new image as the time changes rather that having to reload the page to get the most current time.</p>
  
  <p>If I make the entire page refresh to keep the clock updating every second, then I am prompted everytime to pick a color. I do want that to happen when the page is refreshed though, so I am looking to just refresh the portion of the page that the clock portion runs in. </p>
  
  <p>I have abbreviated the code so that only the first image shows. There are minutes and seconds as well, but they all do pretty much the same thing as far as how they are determined and are displayed.</p>
  
  <p>I have altered the code here to use images from a URL instead of the local folder that the file is kept in so that you can copy/paste it into your preffered HTML editor if you wish. I used TinyURL to shorten the URL in the interest of space.</p>
  
  <pre><code>    &lt;html&gt;
       &lt;head&gt;
       &lt;script type="text/javascript"&gt;
       /*The following two variables are used to determine the hour.*/
       var d = new Date();
       var h = d.getHours();
  
       /*The following variable is used to pick either 1 or "blank" for 
      the first hour digit and display the corresponding image*/
       var h1
       if(h&gt;=1&amp;&amp;h&lt;=9)
       {
       h1=new Array();
       h1[0]=document.createElement('img');
       h1[0].src= "http://tinyurl.com/3qqsggj ";
       h1[1]=document.createElement('img');
       h1[1].src= "http://tinyurl.com/3n75atp ";
       h1[2]=document.createElement('img');
       h1[2].src= "http://tinyurl.com/3tcha7o ";
       } 
      else if(h&gt;=13&amp;&amp;h&lt;=21)
       {
       h1=new Array();
       h1[0]=document.createElement('img');
       h1[0].src= "http://tinyurl.com/3qqsggj ";
       h1[1]=document.createElement('img');
       h1[1].src= "http://tinyurl.com/3n75atp ";
       h1[2]=document.createElement('img');
       h1[2].src= "http://tinyurl.com/3tcha7o ";
       } 
      else
       { 
      h1=new Array();
       h1[0]=document.createElement('img');
       h1[0].src= "http://tinyurl.com/3s8wt8q ";
       h1[1]=document.createElement('img');
       h1[1].src= "http://tinyurl.com/3rz42gw ";
       h1[2]=document.createElement('img');
       h1[2].src= "http://tinyurl.com/3egvtho ";
       }
  
       /*The following function is used to take variable h1 and place 
      the image that corresponds to it into the table in the body*/
       function timewrite()
       {
       document.getElementById("hour1").appendChild(h1[colnum]);
       }
  
       &lt;/script&gt;
       &lt;/head&gt;
       &lt;!--Body runs function timewrite() upon loading--&gt;
       &lt;body onload="timewrite()"&gt; 
       &lt;table border="5" bordercolor="black"&gt;
       &lt;tr&gt;
       &lt;td&gt;
       &lt;span id="hour1"&gt; &lt;!--Here is where the h1 image goes--&gt; &lt;/span&gt;
       &lt;/td&gt;
       &lt;/tr&gt;
       &lt;/table&gt;
       &lt;script type="text/javascript"&gt;
  
       /*The following variable is used to determine whether the image
       for blue, green, or red should be shown.*/
       var col=prompt("Please enter blue, green, or red.");
       col=col.toLowerCase()
  
       /*The following variable converts variable col into a number
       so that it can easily be used to pick the correct h1 array 
      portion in the timewrite() function*/
       var colnum
       if(col=="blue")
       colnum=0;
       else if(col=="green")
       colnum=1;
       else if(col=="red")
       colnum=2;
       else
       colnum=1;
       &lt;/script&gt;
       &lt;/body&gt;
       &lt;/html&gt;
  </code></pre>
  
  <p>Thanks in advance for your help.</p>
  
  <p>I would wonder if setTimeout and/or setInterval would not be effective beause the variables are keeping their values?  As in, are the"d" and "h" variables looing at the time once, taking on those values, and then not changing them unless the page is refreshed?  Do I need to put the variables in a function or something like that, so that they can be refreshed, or will they automatically update as the time changes?
  I am relatively new to JavaScript by the way, in case you were wondering.</p>
  
  <p>Here is a link to the <em>entire</em> code if that will help.  I <em>do</em> realize that it is not the most efficient way to accomplish what I am doing, but I am new to JavaScript, and also, this is a project that needs to contain several different programming concepts.  I have it commented pretty well.
  <a href="http://cid-7cc3864d98261b77.office.live.com/browse.aspx/Shared%20Files?uc=1" rel="nofollow">http://cid-7cc3864d98261b77.office.live.com/browse.aspx/Shared%20Files?uc=1</a></p>