I need to have a script that warns users of leaving without saving changes

$(document).ready(function () {
   $('input').change(function () {
      window.onbeforeunload = function () { return "You still have unsaved changes!" };
  });
});

I found this code, but it goes off when I click the submit button, which is a problem.
Any ideas how I could stop the script going off when I click submit
Thanks in advance

Like this:

$(document).ready(function () {
   $('input').change(function () {
      window.onbeforeunload = function () { return "You still have unsaved changes!" };
  });
  $("#mySubmitButton").click(function() {
    window.onbeforeunload = undefined;
    // OR
    window.onbeforeunload = function() {};
  });
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.