title: Returning a string in Javascript
body: <p>I am trying to create a simple function that will return the correct string when called:</p>
  
  <pre><code>function getState(abbr){
     if (abbr=="WY")
     {
     return "Wyoming";
     }
  }
  </code></pre>
  
  <p>and then the call is like this:</p>
  
  <pre><code>var stateName = getState("WY");
  </code></pre>
  
  <p>However all that is getting returned is: 0</p>
  
  <p>Sorry if I am missing something obvious.</p>
  
  <p>UPDATE - my orig prob was because of a "&amp;" here's the real code I'm dealing with:</p>
  
  <pre><code>function getState(abbr){
      var url = "states.asp"
      var state = ""; 
      $.get(url, function(data) {
          var i = 0;
          $.each($('state',data),function(index, el) {            
              if (abbr == ($(this).attr("abbr"))){
                  //alert($(this).attr("abbr"));
                  state = $(this).text();
              }//if (abbr == $(this).attr("abbr")){
          });//$.each($('state',data),function(index, el) {
      }).success(function() { 
          alert("x" + state);
          return state;
      }); //.success(function() { 
      //$.get(url, function(data) {
      alert("y" + state); 
      return state;
  }
  </code></pre>
  
  <p>I am getting "undefined" as a result to my call: </p>
  
  <pre><code>alert(getState("WY"));
  </code></pre>
  
  <p>Alert("x" + state) works.</p>
  
  <p>UPDATE #2 ---
  here is all that states.asp generates (for now)... later it will return companies, etc:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;STATELIST&gt;
  &lt;STATE abbr="AL"&gt;Alabama&lt;/STATE&gt;
  &lt;STATE abbr="AK"&gt;Alaska&lt;/STATE&gt;
  &lt;STATE abbr="AZ"&gt;Arizona&lt;/STATE&gt;
  &lt;STATE abbr="AR"&gt;Arkansas&lt;/STATE&gt;
  &lt;STATE abbr="CA"&gt;California&lt;/STATE&gt;
  &lt;STATE abbr="CO"&gt;Colorado&lt;/STATE&gt;
  &lt;STATE abbr="CT"&gt;Connecticut&lt;/STATE&gt;
  &lt;STATE abbr="DE"&gt;Delaware&lt;/STATE&gt;
  &lt;STATE abbr="FL"&gt;Florida&lt;/STATE&gt;
  &lt;STATE abbr="GA"&gt;Georgia&lt;/STATE&gt;
  &lt;STATE abbr="HI"&gt;Hawaii&lt;/STATE&gt;
  &lt;STATE abbr="ID"&gt;Idaho&lt;/STATE&gt;
  &lt;STATE abbr="IL"&gt;Illinois&lt;/STATE&gt;
  &lt;STATE abbr="IN"&gt;Indiana&lt;/STATE&gt;
  &lt;STATE abbr="IA"&gt;Iowa&lt;/STATE&gt;
  &lt;STATE abbr="KS"&gt;Kansas&lt;/STATE&gt;
  &lt;STATE abbr="KY"&gt;Kentucky&lt;/STATE&gt;
  &lt;STATE abbr="LA"&gt;Louisiana&lt;/STATE&gt;
  &lt;STATE abbr="ME"&gt;Maine&lt;/STATE&gt;
  &lt;STATE abbr="MD"&gt;Maryland&lt;/STATE&gt;
  &lt;STATE abbr="MA"&gt;Massachusetts&lt;/STATE&gt;
  &lt;STATE abbr="MI"&gt;Michigan&lt;/STATE&gt;
  &lt;STATE abbr="MN"&gt;Minnesota&lt;/STATE&gt;
  &lt;STATE abbr="MS"&gt;Mississippi&lt;/STATE&gt;
  &lt;STATE abbr="MO"&gt;Missouri&lt;/STATE&gt;
  &lt;STATE abbr="MT"&gt;Montana&lt;/STATE&gt;
  &lt;STATE abbr="NE"&gt;Nebraska&lt;/STATE&gt;
  &lt;STATE abbr="NV"&gt;Nevada&lt;/STATE&gt;
  &lt;STATE abbr="NH"&gt;New Hampshire&lt;/STATE&gt;
  &lt;STATE abbr="NJ"&gt;New Jersey&lt;/STATE&gt;
  &lt;STATE abbr="NM"&gt;New Mexico&lt;/STATE&gt;
  &lt;STATE abbr="NY"&gt;New York&lt;/STATE&gt;
  &lt;STATE abbr="NC"&gt;North Carolina&lt;/STATE&gt;
  &lt;STATE abbr="ND"&gt;North Dakota&lt;/STATE&gt;
  &lt;STATE abbr="OH"&gt;Ohio&lt;/STATE&gt;
  &lt;STATE abbr="OK"&gt;Oklahoma&lt;/STATE&gt;
  &lt;STATE abbr="OR"&gt;Oregon&lt;/STATE&gt;
  &lt;STATE abbr="PA"&gt;Pennsylvania&lt;/STATE&gt;
  &lt;STATE abbr="RI"&gt;Rhode Island&lt;/STATE&gt;
  &lt;STATE abbr="SC"&gt;South Carolina&lt;/STATE&gt;
  &lt;STATE abbr="SD"&gt;South Dakota&lt;/STATE&gt;
  &lt;STATE abbr="TN"&gt;Tennessee&lt;/STATE&gt;
  &lt;STATE abbr="TX"&gt;Texas&lt;/STATE&gt;
  &lt;STATE abbr="UT"&gt;Utah&lt;/STATE&gt;
  &lt;STATE abbr="VT"&gt;Vermont&lt;/STATE&gt;
  &lt;STATE abbr="VA"&gt;Virginia&lt;/STATE&gt;
  &lt;STATE abbr="WA"&gt;Washington&lt;/STATE&gt;
  &lt;STATE abbr="WV"&gt;West Virginia&lt;/STATE&gt;
  &lt;STATE abbr="WI"&gt;Wisconsin&lt;/STATE&gt;
  &lt;STATE abbr="WY"&gt;Wyoming&lt;/STATE&gt;
  &lt;/STATELIST&gt;
  </code></pre>