I have a simple form that asks if you are sure you want to submit it.
$(document).ready(function(){ $("form#myform").on('submit', function(e) { if (!confirm('Are you sure?')){ e.preventDefault(); } else { console.log("submitting..."); } }); });
Submit the form, click "ok" at the prompt "are you sure", the form only fines.
- refresh the page, clear the slate -
Submit the form, click "Cancel" to "are you sure." The form does not appear as expected. Submit the form again, click "ok" at the prompt "Are you sure", the form is still not submitted, "Submit ..." is sent to the console. From this point on, the form will never be submitted until I refresh the page and click OK for the first time.
If I change
e.preventDefault ();
from
return false;
nothing changes, exactly the same behavior.
I am completely at a dead end. What am I doing wrong?
edit: Here is the jsFiddle link https://jsfiddle.net/8ac3Lgzg/ . The HTML and JavaScript in this fiddle are / exactly the same / as the code I have in my project. The problem described above is NOT executed when jsFiddle starts, but in my project.
source share