[Answered ]-How do I send a JavaScript confirm response over Django to a script to perform operations based on the response?

2👍

I don’t think that this would be a good way to solve the problem,

try to do this:

in your template.html:

<form method="POST" action="">
    {% csrf_token %}
    <input type="submit" name="delete_amount" onclick="delete_me(event)" />
</form>

in your view.py:

#just in case you have other form
if 'delete_amount' in request.POST:
    # do your deleting query here
    print('deleting amount')

and in your javascript.js:

<script>
function delete_me(e)
{
     if(!confirm('Are you sure you want to delete this?')){
          //prevent sending the request when user clicked 'Cancel'
          e.preventDefault();
     }
}

</script>

Hope this will help!

Leave a comment