Jump to content

Issue With Function Called By Onclick Event


jul
 Share

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...