2 var formHasChanged = false;
4 var form_to_watch = document.getElementById('form_to_watch');
5 form_to_watch.addEventListener('input', function() {
8 form_to_watch.addEventListener('submit', function() {
11 window.addEventListener('beforeunload', function(event) {
12 if (formHasChanged && !submitted) {
13 var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?';
14 event.returnValue = confirmationMessage;
15 return confirmationMessage;