I've got a popup form that appears when clicking on certain markers in a Leaflet map. Once the form is finished, I'd like to send the fields entered, as well as some details about the marker, to a separate function. I've started with just sending the marker for now to test it out, but I've run into an issue.
But when I go to pass my marker through the function and run it through console.log, it returns [Object object] instead of a marker with details about latitude, longitude, and other things.
var newMarker = new VietMarker (map.getCenter(), {
draggable: true
});
var popupHTML = '<form id="add-marker-form">' +
'<div class="form-group">' +
'<label for="marker-title">Title</label>' +
'<input type="text" class="form-control" id="marker-title" required="true">' +
'</div>' +
'<div class="form-group">' +
'<label for="marker-contributor">Contributor</label>' +
'<input type="text" class="form-control" id="marker-contributor">' +
'</div>' +
'<div class="form-group">' +
'<label for="marker-yt-link">Video link</label>' +
'<input type="text" class="form-control" id="marker-yt-link">' +
'</div>' +
'<div class="form-group">' +
'<label for="marker-description">Description</label>' +
'<textarea class="form-control" rows="3" id="marker-description"></textarea>' +
'</div>' +
'<input type="button" id="marker-submit" class="btn btn-primary btn-block" onClick="testMarker(\'' + newMarker + '\');" value="Add to Map" />' +
'</form>';
newMarker.bindPopup(popupHTML).addTo(map);
And in my testMarker() function:
function testMarker (markerToAdd) {
console.log(markerToAdd);
}
Returns [Object object] in console.log, with no sub-fields, instead of a Marker object.
testMarker
. That would just console whatever you pass to it. Why even have such a function? – StackSlavetestMarker
with my button at the end of the form. The syntax is really long so it's scrolled horizontally. I have the function because I wanted to see if it was even being passed what it should be - in the console, I should be able to see the latitude and longitude properties of the marker - but it just says [Object object] and that's it. – user4660280console.log("Some string... " + newMarker + " ...another string");
, and you'll start understanding what's causing the problem :-) – IvanSanchez