home · contact · privacy
Improve todo accounting.
[misc] / todo_templates / watch_form.html
diff --git a/todo_templates/watch_form.html b/todo_templates/watch_form.html
new file mode 100644 (file)
index 0000000..979c1da
--- /dev/null
@@ -0,0 +1,19 @@
+<script>
+    var formHasChanged = false;
+    var submitted = false;
+    var form_to_watch = document.getElementById('form_to_watch');
+    form_to_watch.addEventListener('input', function() {
+        formHasChanged = true;
+    });
+    form_to_watch.addEventListener('submit', function() {
+        submitted = true;
+    });
+    window.addEventListener('beforeunload', function(event) {
+        if (formHasChanged && !submitted) {
+            var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?';
+            event.returnValue = confirmationMessage;
+            return confirmationMessage;
+        }
+    });
+</script> 
+