Skip to content

Instantly share code, notes, and snippets.

@awkale
Created December 18, 2013 21:12
Show Gist options
  • Save awkale/8029916 to your computer and use it in GitHub Desktop.
Save awkale/8029916 to your computer and use it in GitHub Desktop.
Confirm form field change before saving
var needToConfirm = false;
$("input,textarea").on("input", null, null, function() {
needToConfirm = true;
});
$("select").change(function() {
needToConfirm = true;
});
window.onbeforeunload = function(){
if(needToConfirm) {
return "If you exit this page, your unsaved changes will be lost.";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment