Im just wondering if there is a way to call a PHP function within a Javascript file?
So I have a website using google maps API which saves event markers to a map. when the markers are clicked they bring up an info box with details of the event. This info window also has a button and I want to be able to get the ID of that particular event in the DB so its details can be viewed and deleted on another page.
The JS that displays the Info Window:
var eventContent = $('<div class="event-info">' + '<h4 class="event-name">' + point.name + '</h4><hr>' +
'<span><h5>Date: </h5>' +
'<p class="event-date">' + point.edate + '</p></span>' +
'<p class="event-description">'+ point.description +'</p>' +
'<input type="button" id="view-event" class="btn btn-info btn-sm" onclick="showDetails();" value="View Event" />'+
'<a href="#" onclick="removeEvent();" class="btn btn-danger btn-sm">Remove Event</a>' +
'</div>');
// Display Event details on marker click
google.maps.event.addListener(event_markers[i], "click", function () {
infowindow.setContent(eventContent[0]);
infowindow.open(map, event_markers[i]);
I want to call the ID in wither of the buttons, similar to what I have done in another PHP page:
echo "<td><a href='details.php?id=".$row['id']."' target=\"_blank\" class='btn btn-warning btn-sm'>View</a></td>";
Load values into an hidden input and then extract with js...
<script>
$(function(){
var phpvariable = $('input[name="sqlvalue"]').val();
// Now you can use $phpvariable in JS too
});
</script>
<input name="sqlvalue" value="<?=$phpvariable?>" type="hidden" />