0
Guys, I have the following problem:
I have a table with several records and, as soon as a certain link related to the record is clicked, a modal window would be opened with more information related to it.
Link:
<a class="navbar-brand" href="#my_modal" data-toggle="modal" data-book-id="' . $res->codigoLO . '"><i class="fa fa-times"></i></a>
The following script takes a value that is sent by parameter when clicking on the link and the arrow in an input present in the modal window. In fact, I would like instead of this value being put into input, to be assigned directly to a PHP variable also present in the modal window.
<script type="text/javascript">
$('#my_modal').on('show.bs.modal', function (e) {
var bookId = $(e.relatedTarget).data('book-id');
$(e.currentTarget).find('input[name="bookId"]').val(bookId);
});
</script>
Any idea how I can do that?
You cannot set variables in PHP by Javascript. PHP runs on the server side, while javascript runs on the browser (client side)
– Callebe
Complementing what @Callebe said: when Javascript runs, PHP has long since finished its service, there are no more PHP variables in this context.
– bfavaretto