title: Why JavaScript throwing 'Uncaught ReferenceError: var is not defined' when var is defined
body: <p>My JavaScript function</p>
  
  <pre><code>function B_modeWindow (id,cords) {  
      loading();
  
      var xmlhttp;
  
      if (window.XMLHttpRequest) {
          xmlhttp=new XMLHttpRequest();
      } else {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
  
              var cords = document.getElementById(cords)
              cords.innerHTML=xmlhttp.responseText;
              var xy = cords.split("x");          
              hideloading();
          }
      }
  
      xmlhttp.open("GET","processMapEdit.php?id="+id+"&amp;x="+xy[0]+"&amp;y="+xy[1],true);
      xmlhttp.send();
  }
  </code></pre>
  
  <p>returns: </p>
  
  <pre><code>Uncaught ReferenceError: xy is not defined 
  </code></pre>
  
  <p>in:</p>
  
  <pre><code>xmlhttp.open("GET","processMapEdit.php?id="+id+"&amp;x="+xy[0]+"&amp;y="+xy[1],true);
  </code></pre>
  
  <p>It seems that xy is just not there, but it's defined just 5 lines above! What is wrong here?</p>