Maps - Codeigniter

Asked

Viewed 90 times

0

Personal I am using the following library to work with maps: http://biostall.com/codeigniter-google-maps-v3-api-library/ .

Here is the tutorial of the same: http://biostall.com/demos/google-maps-v3-api-codeigniter-library/mapclick .

I’d like when I click on the map not to climb one alert, but the data were for 2 inputs. To increase the alert the following command is used:

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

But I do not know much javascript and I have no idea how to pass the value to the 2 inputs, I appreciate who can help me.

1 answer

0


You can use the function val() of Jquery.

Example script to play the 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();

This 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();';

Your inputs would have to be so to suit the example, having to have the attribute id for jquery to locate the control:

<input type="text" id="txtLatitude" name="latitude">
<input type="text" id="txtLongitude" name="longitude">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.