I have tested many times and it seems Javascript error inside a Console.
Javascript contains two ID’s and searchInput name is the same inside Javascript. Should be modified also searchInput name as there are two ID’s?
var searchInput = ‘ID1’;
var searchInput = ‘ID2’;
How to manage this problem?
var searchInput = 'search_input';
$(document).ready(function ()
{
var autocomplete;
autocomplete = new google.maps.places.Autocomplete((document.getElementById(searchInput)),
{
types:['geocode'],
}
);
I believe what he’s trying to say is he wants both of his fields to be instantiated as Autocomplete objects.
To do that, you’d have to run the line twice, with different variable names.
I did not post an error as it was a conflict inside Geo autocomplete script.
If I put doubled script, we should change
var searchInput = ‘ID1’; and also put var searchInput = ‘ID1’;. But Google Console error showed an error and I removed one script and it worked without an issue.
So, I try to manage ID’s. Inside HTML there are two ID’s and it is allowed.
var searchInput = ‘ID1’;
var searchInput = ‘ID2’;
A problem arise as you quoted:with different variable names.
var searchInput = ‘ID1’;
var searchInput = ‘ID2’;
They are different ID’s, but what else should be modified to make it twice? Is it an issue with the same name like searchInput
getElementById(searchInput
var searchInput = 'ID1';
$(document).ready(function ()
{
var autocomplete;
autocomplete = new google.maps.places.Autocomplete((document.getElementById(searchInput)),
{
types:['geocode'],
}
);
google.maps.event.addListener(autocomplete, 'place_changed', function ()
{
var near_place = autocomplete.getPlace();
document.getElementById('latvalue').value = near_place.geometry.location.lat();
document.getElementById('lngvalue').value = near_place.geometry.location.lng();
document.getElementById('latshow1').innerHTML = near_place.geometry.location.lat();
document.getElementById('lngshow1').innerHTML = near_place.geometry.location.lng();
}
);
}
);