title: ASP.NET Javascript Zip Code Lookup for CIty and State w/ Mootools, jQuery, or Ajax
body: <p>I'm trying to write a Javascript Zip Code lookup utility. </p>
  
  <p>1) The User will select a State from a drop down. </p>
  
  <p>2) The City Drown Down will then be populated based on the State selected</p>
  
  <p>3) A textbox below is then populated with the corresponding Zip Code(s) based on Selected State and Zip Code on an ASP.NET page. </p>
  
  <p>Problem:  I get the error Request() is not defined which causes the application to hault when a State is selected.  </p>
  
  <p>What should I cahnge in the following code? </p>
  
  <pre><code>  &lt;script language="javascript"&gt;
     var request = new Request();
     var url = "";
  
     function getZipCode()
     {    
  request.GetNoCache(url + "getZipCode.aspx?City=" +document.getElementById("drpCity").options[document.getElementById("drpCity").selectedIndex].value+ "&amp;State=" +document.getElementById("drpStateSearch").options[document.getElementById("drpStateSearch").selectedIndex].value,      
  function(result)
  {
      if (result.readyState!=ReadyState.Complete)
          return;             
      if (result.status==HttpStatus.OK &amp;&amp; result.responseText != "")
      {
          var zip = result.responseText;
          document.getElementById("txtZip").value = zip;
      }
      else
      {
          document.getElementById("txtZip").value = "No Zip Found";
      }
  }
  )
    }
  
  
  
     function selectCity()
     {    
  request.GetNoCache(url + "getCities.aspx?State=" +document.getElementById("drpStateSearch").options[document.getElementById("drpStateSearch").selectedIndex].value,         
  
  function(result)
  {
  
      if (result.readyState!=ReadyState.Complete)
          return;             
      if (result.status==HttpStatus.OK &amp;&amp; result.responseText != "")
      {
          var cities = result.responseText;
          var city_array=cities.split(",");
          var len = document.getElementById("drpCity").options.length;
  
          for( var j=len; j&gt;=0;j--)
          {
              document.getElementById("drpCity").options[j]=null;
          }
  
          var option_i = new Option("--Select--","--Select--");
          document.getElementById("drpCity").options[0] = option_i;
  
          for(var i=1; i&lt;=city_array.length-1;i++)
          {
              var option_c = new Option(city_array[i-1],city_array[i-1]);
              document.getElementById("drpCity").options[i] = option_c;
          }
      }
      else
      {
          var option_c = new Option("No City","");
          document.getElementById("drpCity").options[0] = option_c;
      }
  }
  )
     }
  
              &lt;/script&gt;
     &lt;script language="javascript" type="text/javascript"&gt;
     &lt;!--
  function __doPostBack(eventTarget, eventArgument) {
      var theform;
      if (window.navigator.appName.toLowerCase().indexOf("microsoft") &gt; -1) {
          theform = document.Form2;
      }
      else {
          theform = document.forms["Form2"];
      }
      theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
      theform.__EVENTARGUMENT.value = eventArgument;
      theform.submit();
  }
     // --&gt;
     &lt;/script&gt;
  
              City: &lt;select id="drpStateSearch" name="drpStateSearch" 
                  onchange="Javascript:selectCity();" style="width: 120px;"&gt;
                  &lt;option value=""&gt;---Select---&lt;/option&gt;
                  &lt;option value="AK"&gt;Alaska&lt;/option&gt;
                  &lt;option value="AL"&gt;Alabama&lt;/option&gt;
                  &lt;option value="AR"&gt;Arkansas&lt;/option&gt;
                  &lt;option value="AZ"&gt;Arizona&lt;/option&gt;
                  &lt;option value="CA"&gt;California&lt;/option&gt;
                  &lt;option value="CO"&gt;Colorado&lt;/option&gt;
                  &lt;option value="CT"&gt;Connecticut&lt;/option&gt;
                  &lt;option value="DC"&gt;District of Columbia&lt;/option&gt;
                  &lt;option value="DE"&gt;Delaware&lt;/option&gt;
                  &lt;option value="FL"&gt;Florida&lt;/option&gt;
                  &lt;option value="GA"&gt;Georgia&lt;/option&gt;
                  &lt;option value="HI"&gt;Hawaii&lt;/option&gt;
                  &lt;option value="IA"&gt;Iowa&lt;/option&gt;
                  &lt;option value="ID"&gt;Idaho&lt;/option&gt;
                  &lt;option value="IL"&gt;Illinois&lt;/option&gt;
                  &lt;option value="IN"&gt;Indiana&lt;/option&gt;
                  &lt;option value="KS"&gt;Kansas&lt;/option&gt;
                  &lt;option value="KY"&gt;Kentucky&lt;/option&gt;
                  &lt;option value="LA"&gt;Louisiana&lt;/option&gt;
                  &lt;option value="MA"&gt;Massachusetts&lt;/option&gt;
                  &lt;option value="MD"&gt;Maryland&lt;/option&gt;
                  &lt;option value="ME"&gt;Maine&lt;/option&gt;
                  &lt;option value="MI"&gt;Michigan&lt;/option&gt;
                  &lt;option value="MN"&gt;Minnesota&lt;/option&gt;
                  &lt;option value="MO"&gt;Missouri&lt;/option&gt;
                  &lt;option value="MS"&gt;Mississippi&lt;/option&gt;
                  &lt;option value="MT"&gt;Montana&lt;/option&gt;
                  &lt;option value="NC"&gt;North Carolina&lt;/option&gt;
                  &lt;option value="ND"&gt;North Dakota&lt;/option&gt;
                  &lt;option value="NE"&gt;Nebraska&lt;/option&gt;
                  &lt;option value="NH"&gt;New Hampshire&lt;/option&gt;
                  &lt;option value="NJ"&gt;New Jersey&lt;/option&gt;
                  &lt;option value="NM"&gt;New Mexico&lt;/option&gt;
                  &lt;option value="NV"&gt;Nevada&lt;/option&gt;
                  &lt;option value="NY"&gt;New York&lt;/option&gt;
                  &lt;option value="OH"&gt;Ohio&lt;/option&gt;
                  &lt;option value="OK"&gt;Oklahoma&lt;/option&gt;
                  &lt;option value="OR"&gt;Oregon&lt;/option&gt;
                  &lt;option value="PA"&gt;Pennsylvania&lt;/option&gt;
                  &lt;option value="RI"&gt;Rhode Island&lt;/option&gt;
                  &lt;option value="SC"&gt;South Carolina&lt;/option&gt;
                  &lt;option value="SD"&gt;South Dakota&lt;/option&gt;
                  &lt;option value="TN"&gt;Tennessee&lt;/option&gt;
                  &lt;option value="TX"&gt;Texas&lt;/option&gt;
                  &lt;option value="UT"&gt;Utah&lt;/option&gt;
                  &lt;option value="VA"&gt;Virginia&lt;/option&gt;
                  &lt;option value="VT"&gt;Vermont&lt;/option&gt;
                  &lt;option value="WA"&gt;Washington&lt;/option&gt;
                  &lt;option value="WI"&gt;Wisconsin&lt;/option&gt;
                  &lt;option value="WV"&gt;West Virginia&lt;/option&gt;
                  &lt;option value="WY"&gt;Wyoming&lt;/option&gt;
              &lt;/select&gt; &lt;br /&gt;
              State: &lt;select id="drpCity" name="drpCity" onchange="javascript:getZipCode()"&gt;
                  &lt;option selected=""&gt;Select State to Populate&lt;/option&gt;
              &lt;/select&gt;
              &lt;br /&gt;
              &lt;table id="Table6" border="0" cellpadding="0" cellspacing="0" width="100%"&gt;
                  &lt;tr&gt;
                      &lt;td height="28" width="38%"&gt;
                          Zipcode:&lt;/td&gt;
                      &lt;td height="28" width="62%"&gt;
                          &lt;input id="txtZip" name="txtZip" type="text" /&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Thanks! </p>