title: Javascript variable not acting global
body: <p>I'm just learning Javascript after starting out in PHP.</p>
  
  <p>I'm trying some basic stuff, but for some reason the below code doesn't act as I expect.  I have researched it, and from what I can tell it should work.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  showIndex=4;
  
  function test(){
  showIndex++;
  alert(showIndex);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I am calling the script with an image:</p>
  
  <pre><code>&lt;div style="display:inline-block;margin-left:25px;"&gt;';
  &lt;a href="" onclick="test()" &gt;&lt;img src="_images/next.png" width="100" /&gt;    &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>It runs fine the first time, but when I hit the button again, it still has the initial variable plus one. (which makes me think it's acting as a local variable...)
  It seem so straight forward... what am I doing wrong?</p>