jul Posted December 3, 2009 Share Posted December 3, 2009 hi,I'm doing some geocoding using the google maps API.The user fill a form with some address, and when the submit button is clicked, a codeAddress() function is called, which is supposed to perform the geocoding, but it does not work.As a test, I hardcoded the address and call the codeAddress function when the document is loaded.When codeAddress is called when the page is ready, it works ok, but when it's called by the onclick event, it doesn't work (no errors returned by firebug, but it's like the geocoding service is not called).Anybody can help?Thanksthe javascript $(function(){codeAddress();});function codeAddress() { var geocoder = new google.maps.Geocoder(); var address = "paseo montjuic, 30, barcelona, spain"; if (geocoder) { geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { alert(results[0].geometry.location.lat()); } else { alert("Geocode was not successful for the following reason: " + status); } }); } } the HTML <form action="/restaurant/add/" method="POST"><!-- stuff --><p style="clear: both;"><input type="submit" value="Submit" onclick="codeAddress()" /></p></form> Link to comment Share on other sites More sharing options...
thescientist Posted December 3, 2009 Share Posted December 3, 2009 maybe you need to return: false after the onClick event? Link to comment Share on other sites More sharing options...
jul Posted December 4, 2009 Author Share Posted December 4, 2009 maybe you need to return: false after the onClick event?Thanks, it works! Link to comment Share on other sites More sharing options...
thescientist Posted December 4, 2009 Share Posted December 4, 2009 Thanks, it works!hah, I owe that little nugget to Dierdre's Dad... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.