title: get city and state from zip code entered javascript
body: <p>I have an existing DB that contains city, state, zip, lat, long, county:  40,000+ records.</p>
  
  <p>I am able to use it with no problems.</p>
  
  <p>What I'm trying to do now is when a user enters a zip code in a form, query the DB and get the associated city, state, lat, long, and county.</p>
  
  <p>The script executes "ONBLUR" but nothing happens.  I verified that I'm calling the function right because I inserted a <code>window.alert("Test")</code>.</p>
  
  <p>Here is the javascript:</p>
  
  <pre><code>function updateCityState()
     {
     {
      var zipValue = document.getElementById('zipcode').value;
      if(zipValue!="")
      {
          var url = "admin/includes/zip_check.php";
          var param = "?zip=" + escape(zipValue);
  
          var ajax = getHTTPObject();
  
          ajax.open("GET", url + param, true);
          ajax.onreadystatechange = handleAjax;
          ajax.send(null);
      }
  }
  }
   function handleAjax()
  {
  if (ajax.readyState == 4)
  {
      citystatearr = ajax.responseText.split(",");
  
      var city = document.getElementById('city');
      var state = document.getElementById('state');
  
      city.value = citystatearr[0];
      state.value = citystatearr[1];
  }
   }
  </code></pre>
  
  <p>My "zip_check.php" file looks like this.... The zip_check works when I query it manually...</p>
  
  <pre><code>include_once("../db.php");
  $query = "SELECT * FROM `cities_extended` WHERE `zip`=".mysql_real_escape_string($_GET['zip']);
  $result = mysql_query($query) or die(mysql_error());
  
  
  $row = mysql_fetch_array($result);
  echo $row['city'].",".$row['state_code'];
  </code></pre>
  
  <p>Do I need to include something like JQuery or something else that I'm missing for this to work?  Is my syntax correct?</p>