title: How to prevent javascript alert on exit when user clicks on submit button
body: <p>I have the following js code installed on a form page to alert the user if he attempts to leave the page in the middle of filling out a form:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    window.onbeforeunload = function (evt) {
    var message = 'Data you entered may not be saved';
    if (typeof evt == 'undefined') {
    evt = window.event;
    }
    if (evt) {
    evt.returnValue = message;
    }
    return message;
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>It works fine when user clicks on other links or tabs in an attempt to navigate away from the page. But the javascript message pops up even when the user clicks on the submit button to submit changes in the form.</p>
  
  <p>How do I prevent this js message from popping up when the form is submitted?</p>