It sounds like what you want to do is to prevent the onbeforeunload
message from showing when you submit the form.
Simply add a submit
handler that returns the form_has_been_modified
value to false.
$("#additemform").on('submit', function(e) {
form_has_been_modified = false;
});
In this demo I also cleaned up your example, removing unnecessary handlers and changed form_has_been_modified
to use the native boolean true
and false
instead of 0 and 1.