home · contact · privacy
Improve todo accounting.
[misc] / todo_templates / watch_form.html
1 <script>
2     var formHasChanged = false;
3     var submitted = false;
4     var form_to_watch = document.getElementById('form_to_watch');
5     form_to_watch.addEventListener('input', function() {
6         formHasChanged = true;
7     });
8     form_to_watch.addEventListener('submit', function() {
9         submitted = true;
10     });
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;
16         }
17     });
18 </script> 
19