Hi there,
I am trying to pass data to a modal but right now it isnt working.
My Button to open the modal:
<button class="btn btn-info" data-toggle="modal" data-target="#edit" data-mytitle="Hello">Edit</button>
My modal window
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="title" class="col-form-label">Title: </label>
<input type="text" class="form-control" id="title" name="title">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
My script attached to that blade template below the modal window:
<script>
$('#edit').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var title = button.data('mytitle')
var modal = $(this)
modal.find('.modal-body #title').val(title);
})
</script>
Also, I included jquery in the main layout file (so jquery i included on all pages - reference is working):
<script src="{{ asset('js/jquery-3.5.1.min.js') }}"></script>
Can anyone help me here? Right now, the modal shows no data.