I have Google Maps Autocomplete working on severalinput
tags like this:
<input class="controls pac-input" id="pac-input" type="text" onfocus="geolocate()" placeholder="Type custom address" />
To enable Google Maps auto-complete, I have the following code:
//https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
$(document).ready(function () {
autocomplete = new google.maps.places.Autocomplete((document.getElementById('pac-input')), { types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', function () {
MyFunc();
});
});
And then, in the MyFunc()
function I do what I need:
function MyFunc() {
var fullAddress = autocomplete.getPlace().formatted_address;
var input = $(this);
//stuff that uses input
}
This code however, has two problems:
- The first is that i am using an Id, to affect multiple input boxes (I have many input fields). I tried selecting by class but it fails with error ′undefined′. How can I apply that function to a collection of input fields?
- How do I know which field is being clicked? I tried using the jquery
$(this)
but it aint working. How can jQuery help me ?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…