This has already been asked, I know, but I don't understand why this isn't working for me.
Trying to detect form changes, and if the user tries to navigate away, I want them to confirm that they will lose their changes...
var dirty = false;
$("form#add_item :input").change(function() {
dirty = true;
});
$("window").on('beforeunload', function() {
if (dirty) {
return 'You have unsaved changes! If you leave this page, your changes will be lost.';
}
});