Im trying to run a Function after the user select a address on the Google Address List. I tried with onBlur
but the action would fire before the user could select the address giving me an incomplete one.
I read these topics:
How to fire place_changed event for Google places auto-complete on Enter key
Google Places API - place_changed listener not working
Events other than 'place_changed' for Google Maps Autocomplete
And I tried with place_changed
but still I cant get to run my function.
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=EDITED(MY KEY)&libraries=places"></script><script src="mapa.js" language="Javascript" type="text/javascript"></script>
<script type="text/javascript" src="jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
</head>
<body>
<input type="text" name="street" id="0" onFocus="autoComplete(this);">
</body>
</html>
JavaScript
function autoComplete(adress)
{
var input = document.getElementById(adress.id);
var options = { componentRestrictions: {
country: 'fr'
}};
new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(gmaps, 'place_changed', function () {
getPlace(adress);
});
}
function getPlace(adress)
{
alert(adress.value);
}
What I am missing?
For an alternative solution is there anyway to make the onBlur
or onChange
only fire after the user select something on the auto complete list? This would be a better solution to my problem I think.
Any help is appreciated.