Remember checkbox state across page views
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Mon, 16 May 2011 15:11:38 -0600
changeset 129 c1cfeffea597
parent 128 7b4be901a3fb
child 130 a7f63ad59c30
Remember checkbox state across page views

Firefox already does this, but other browsers don't, and it's annoying.
autoimplementation.html
--- a/autoimplementation.html	Mon May 16 14:56:46 2011 -0600
+++ b/autoimplementation.html	Mon May 16 15:11:38 2011 -0600
@@ -81,6 +81,8 @@
 <label><input id=alert-checkbox type=checkbox checked onclick='updateAlertRowStyle()'> Display non-alert rows</label>
 
 <script>
+// Confusingly, we're storing a string here, not a boolean.
+document.querySelector("#alert-checkbox").checked = localStorage["display-alerts"] != "false";
 function updateAlertRowStyle() {
 	var checked = document.querySelector("#alert-checkbox").checked;
 	var style = document.querySelector("#alerts");
@@ -89,6 +91,7 @@
 	} else if (!checked) {
 		style.textContent = style.textContent.replace(/(\/\* | \*\/)/g, "");
 	}
+	localStorage["display-alerts"] = checked;
 }
 updateAlertRowStyle();
 </script>