I have the following JS code in my HTML, but no confirm windows shows when pressing the button - what is wrong?

    function confirmSubmit() {
    var retVal = confirm("Are you sure you want to cancel");
    if (retVal == true) {
        return true;
    } else {
        return false;

And within a form the following button

<form action="{% url 'listing' listing.id %}" method="POST">    
     <button name="end" type="submit" class="btn btn-danger" onClick="return confirmSubmit();">Close listing</button>
  • Try changing onClick to onclick
    – Vsjain
    Mar 18, 2021 at 13:37
  • I tried that, but still don't work...
    – Alexander
    Mar 18, 2021 at 14:50

1 Answer 1


Solved it - I had to put the script inside the layout.html's heading tag!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .