I have a modal window for deleting comments. It looks like this:
<div id="deleteModal" class="modal">
<div class="modal-content">
<img class="modal-image" src="{% static 'img/icon-modal-delete.png' %}" alt="DELETE">
<h1 class="modal-title">Delete comment?</h1>
<div class="modal-block">
<form method="POST">
{% csrf_token %}
<button class="modal-sucsess" type="submit">Delete</button>
</form>
<a class="modal-cancel" onclick="closeModal()">Cancel</a>
</div>
</div>
</div>
I include it with the include tag in the django template. There is also a js script for opening and closing the modal window, which looks like this:
function openModal() {
var modal = document.querySelector('.modal');
modal.style.display = 'block';
}
function closeModal() {
var modal = document.querySelector('.modal');
modal.style.display = 'none';
}
In the django template I have a cycle where I display comments to the publication and each comment has a delete button, which on click calls a modal window, it looks like this:
<a class="main-row-content-comments-users-info-delete" onclick="openModal()" >Delete</a>
I wrote a view to delete a comment, but it needs to pass the comment id. If I were doing this directly via a link in a template tag, I would simply pass comment.pk, but how do I pass the key to the modal so that when I click the delete button in the modal, the delete view is called?
I tried to solve this using Ajax requests, but I don’t understand how.