Maps - CodeIgniter

0

Personally I'm using the following library to work with maps: link .

Here's the tutorial: link .

I would like when I clicked on the map not to raise a alert , but rather that the data was for 2 inputs. To raise alert the following command is used:

$config['onclick'] = 'alert(\'You just clicked at: \' + event.latLng.lat() + \', \' + event.latLng.lng());';

But I do not handle much of javascript and I have no idea how to pass the value to the 2 inputs, thank you who can help me.

    
asked by anonymous 09.11.2016 / 15:27

1 answer

0

You can use the val() function of Jquery .

Example script to play value in input (text-box) with Jquery

$("#txtLatitude").val(event.latLng.lat());
$("#txtLongitude").val(event.latLng.lng();

With pure JavaScript

document.getElementById("txtLatitude").value = event.latLng.lat();
document.getElementById("txtLongitude").value = event.latLng.lng();

It would look like your configuration with Jquery

$config['onclick'] = '$("#txtLatitude").val(event.latLng.lat()); $("#txtLongitude").val(event.latLng.lng());';

Your configuration with pure JavaScript:

 $config['onclick'] = 'document.getElementById("txtLatitude").value = event.latLng.lat();document.getElementById("txtLongitude").value = event.latLng.lng();';

Its inputs would have to be like this to fit the example, having to have the id attribute for the jquery to locate the control:

<input type="text" id="txtLatitude" name="latitude">
<input type="text" id="txtLongitude" name="longitude">
    
09.11.2016 / 17:30