I've got a form to get an address from a user, and send that address to my server. The goal is to use Google's geocoding to ensure that the address is unique and geocodable prior to bothering the server with it.
I can successfully bind form.submit, geocode, get my placemarks, insure that they're unique or not.. but I'm totally incapable of making submit work in my callback. Which makes me think I shouldn't be doing it in my callback, but that's why I'm here.
Basically, I need a way to have submit on a form call my validation, which triggers a callback -- if/when that callback is successful, the callback needs to be able to submit the form (not an AJAX post, thanks) without triggering the validation again.
Pseudocode follows, typed from memory.. I've tried both .unbind('submit').submit() and calling the DOM submit directly, neither worked, but I'm including them both here for the hell of it.
<html>
<head>
<!-- .. load google maps and jquery .. -->
<script type="text/javascript">
$(document).ready(function() {
// ... insure Google, get geocoder, etc.
geocoder = ...;
function geocodeCallback(result) {
// .. check if result was a success, and unique
if (.. yes, success ..) {
// use my not-included snazzy function to normalize the address
$('#loc').val(normalize(result.Placemark[0]));
$('#myform').unbind('submit');
$('#myform')[0].submit(); // see note above
} else {
// do something magically useful
}
}
$('#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>