title: in Jquery how to run code with callback before submit
body: <p>I need to run some jquery code before submitting a form and there seem to be some issues.</p>
  
  <p>Just hear me out before you rush to recommend this:</p>
  
  <pre><code>$(function() {
       $('form').submit( function() {
           /* some code */
           return true;
       });
  });
  </code></pre>
  
  <p>I need , after pressing the "submit" button first calculate the longtitude and latitude variables of an address using google API and then submit the form. That requires listening for a response in a callback function.</p>
  
  <p>The code I have so far looks like this:</p>
  
  <pre><code>  $("form input:submit").click(function(e){
        e.preventDefault();
        var address = $(this).find('.address').val();
        geocoder.geocode( { 'address': unescape(address)}, function(results, status) 
        {
            if (status == google.maps.GeocoderStatus.OK) 
            {
              $(".latSelector input:hidden").val(results[0].geometry.location.lat());
              $(".lngSelector input:hidden").val(results[0].geometry.location.lng());
              $("form").submit();
            }
         });  
    });
  </code></pre>
  
  <p>If I do the same using the "submit" function, the form submits before the callback function is triggered and the code behind executes with missing values. </p>
  
  <p>If I use the "click" event on the button like the code above and submit manually, then the code executes correctly but the submit doesn't trigger the code behind of the form.</p>
  
  <p>I think I am close to getting this to work but I can't find the magic combination that will run the code, process the callback values and then submit the form correctly, so that the code behind executes.</p>