0

The following codes reflect the data from the map as html I want to use the information from input value How can I do this?


document.getElementById('location').innerHTML = place.formatted_address;
document.getElementById('lat').innerHTML = place.geometry.location.lat();
document.getElementById('lon').innerHTML = place.geometry.location.lng();


<ul id="geoData">
    <li>Location: <span id="location"></span></li>
    <li>Latitude: <span id="lat"></span></li>
    <li>Longitude: <span id="lon"></span></li>
</ul>

I want to get these codes as input value but I couldn't do it my javascript knowledge is a bit bad

I tried these codes but didn't

document.getElementById('location').value = place.formatted_address;
document.getElementById('lat').value = place.geometry.location.lat();
document.getElementById('lon').value = place.geometry.location.lng();

<input type="hidden" name="adres" id="location" value="">
<input type="hidden" name="lat" id="lat" value="">
<input type="hidden" name="lon" id="lon" value="">

Thuy Rayn
  • 33
  • 6
  • 5
    IDs have to be unique on the page for your code to work properly. Your inputs have the same IDs as your spans. – thmsdnnr Jul 25 '19 at 00:32
  • @thmsdnnr the above codes are the default codes. The code below is my experiment – Thuy Rayn Jul 25 '19 at 00:35
  • @admcfajn I have already done the same thing above but the value does not change the value of this problem .. – Thuy Rayn Jul 25 '19 at 00:39
  • How are you verifying that the value does not change? – Phil Jul 25 '19 at 00:40
  • 1
    [Does your JavaScript come after the ``s?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – AuxTaco Jul 25 '19 at 00:43
  • It can be a possibility that the javascript cannot find ```place.geometry.location.lat()``` and therefore is returning ```undefined``` . – Daggie Blanqx - Douglas Mwangi Jul 25 '19 at 00:43
  • [link](http://www.expertphp.in/article/autocomplete-search-address-form-using-google-map-and-get-data-into-form-example) I've solved my problem with the source here thanks – Thuy Rayn Jul 25 '19 at 00:55

0 Answers0