Confirmation before submitting form using jQuery
Use following line of code on your submit button
onclick="if (confirm('some text')) return true; else return false;"
Example
<form id="delete" action="{% url 'item_delete' item.id %}" method="post">{% csrf_token %}
<input class="floatright" type="submit" onclick="if (confirm('some text')) return true; else return false;" value="Delete" />
$('#delete').submit(function(event){
if(!confirm("some text")){
event.preventDefault();
}
});
You are submitting the form and after are checking for confirm, you need to the inverse
JS:
$(function() {
$("#delete_button").click(function(){
if (confirm("Click OK to continue?")){
$('form#delete').submit();
}
});
});
HTML:
<form id="delete" action="{% url 'item_delete' item.id %}" method="post">{% csrf_token %}
<input id="delete_button" class="floatright" type="button" value="Delete" />
</form>