Javascript function on submit button - Wait for it to complete
<p>I want to trigger a function when the submit button is pressed on the form and wait for the javascript function to complete, then continue the form submission. I dont want the form to submit before the javascript function has completed.**</p>

<p>This is what I have at the moment:
<a href="http://jsfiddle.net/njDvn/68/" rel="nofollow">http://jsfiddle.net/njDvn/68/</a></p>

<pre><code>function autosuggest() {
var input = document.getElementById('location');
    var options = {
    types: [],
    };
    var autocomplete = new google.maps.places.Autocomplete(input, options);
}

&lt;!-- Get lat / long --&gt;      
function getLatLng() {
    var geocoder = new google.maps.Geocoder();
    var address = document.getElementById('location').value;
    geocoder.geocode({
        'address': address
    }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var latLng = results[0].geometry.location;
            $('#lat').val(results[0].geometry.location.lat());
            $('#lng').val(results[0].geometry.location.lng());
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

&lt;!-- Load it --&gt; 
window.onload = autosuggest;
</code></pre>
