I have list of lat/lng stored in DB
If checkbox is checked I am getting the value in an array name='checkbox[]'.
Consider my HTML is:
<input type="checkbox" value="123,456" />
<input type="checkbox" value="789,1011" />
I'd like the resulting data in that form (array of objects)
[
{lat: "123", lng: "456"},
{lat: "789", lng: "1011"}
]
I tried this one, but it does not split and store data in lat and lng
$(document).ready(function() {
var tmp = [];
$("input[name='checkbox[]']").change(function() {
var checked = $(this).val();
if ($(this).is(':checked')) {
tmp.push(checked);
const [lat1[], lon1[]] = tmp.split(',');
} else {
tmp.splice($.inArray(checked, tmp), 1);
}
});
$('#show_all_point').on('click', function() {
alert(lat1, lon1);
});
});