Q:

Confirm leaving of page unless leaving by form submission

I have a page containing a form where I would like to prompt the user to confirm to leave the page if they have started entering form data unless, of course, they leave the page by submitting the form. How can I bypass the below code if the form has been submitted causing the page change?
$(document).ready(function(){
        window.onbeforeunload = function () {

                return "If you leave this page before submitting your information to us you will need to reenter it again.";

        }
    })

A:

Just add a flag to follow the status of the submission (false at initialization, true when form has been submitted), then you check it in your function().

