I have a delete button that deletes an object from the database. This button has a js windows.confirm function for deletion. I need to pass servico.id to function so I can reference the object in the view. How do I do this?
<a href="#" class="btn btn-danger btn-sm" onclick="return myFunction()">Delete</a>
Script
<script>
function myFunction() {
if (window.confirm("Você tem certeza que deseja excluir ?")) {
window.location.href="{% url 'servico:excluir-servico' servico.id %}";
}
}
</script>
html
<a href="#" data-id="{{servico.id}}" id="de" class="btn btn-danger btn-sm" onclick="return myFunction()">Delete</a>
js
<script>
function myFunction() {
if (window.confirm("Você tem certeza que deseja excluir ?")) {
_id = $('#').attr(''data-id)
window.location.href="`${window.location.pathname}/${_id}`;";
}
}
</script>
I used jquery you need to include it.