Jump to content

Issue With Function Called By Onclick Event


jul

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...