JavaScript Form Submit – Confirm or Cancel Submission Dialog Box

A simple inline JavaScript confirm would suffice: <form onsubmit=”return confirm(‘Do you really want to submit the form?’);”> No need for an external function unless you are doing validation, which you can do something like this: <script> function validate(form) { // validation code here … if(!valid) { alert(‘Please correct the errors in the form!’); return false; … Read more

How to show the “Are you sure you want to navigate away from this page?” when changes committed?

Update (2017) Modern browsers now consider displaying a custom message to be a security hazard and it has therefore been removed from all of them. Browsers now only display generic messages. Since we no longer have to worry about setting the message, it is as simple as: // Enable navigation prompt window.onbeforeunload = function() { … Read more