title: Waiting for javascript async callback @ http post
body: <p>I'm implementing a small feature and kind of stuck.</p>
  
  <p>I have a button to execute some action, such as</p>
  
  <pre><code>&lt;input type="submit" value="My Button" onclick="javascript:DoSomething();" /&gt;
  </code></pre>
  
  <p>When the user clicks the button the function DoSomething is called.</p>
  
  <pre><code>    function DoSomething()
      {
          var geocoder = new GClientGeocoder();
          geocoder.getLocations(map.getCenter(), function SetField(response)
            {
              if (!response || response.Status.code != 200) 
              {
                 alert("Status Code:" + response.Status.code);
              } 
              else 
              {
                  var place = response.Placemark[0];
                  $('#someHiddenField')[0].value = place.AddressDetails.Country.CountryNameCode;
              }
            });
  }
  </code></pre>
  
  <p>Inside the function a callback function is defined, which performs an async operation that writes a city name in a form field. The problem is that the async callback will try to write in the field after the page is posted. Is there any was I can make the post process wait for the callback result? The callback is defined in the Google Maps API and I cannot avoid it.</p>
  
  <p>Thanks in advance</p>