I have a form to get an address from a user and send this address to my server. The goal is to use Google geocoding to ensure that the address is unique and geocode before bothering it with the server.
I can successfully bind form.submit, geocode, get my tags, assure that they are unique or not .. but I am completely unable to do the submit job in my callback. This makes me think that I should not do this in my callback, but that is why I am here.
Basically, I need a way to send my verification call to the form, which calls the callback - if / when this callback is successful, the callback should be able to send the form (and not an AJAX message, thanks) without restarting the verification.
Pseudo code follows, printed from memory .. I tried both .unbind ('submit'). submit () and calling the DOM submit directly didn't work, but I include both of them here, damn it.
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
geocoder = ...;
function geocodeCallback(result) {
if (.. yes, success ..) {
$('#loc').val(normalize(result.Placemark[0]));
$('#myform').unbind('submit');
$('#myform')[0].submit();
} else {
}
}
$('#myform').bind('submit', function() {
geocoder.getLocations($('#loc').val(), geocodeCallBack);
return false;
});
});
</script>
</head>
<body>
<form id="myform" method="post" action="thispage.html">
<input type="text" name="loc" />
<input type="submit" name="sub" value="Submit" />
</form>
</body>
</html>
source
share