I've noticed that in Firefox an input element maintains its value when the page is reset but not in Safari. Is there a way to maintain the values a user would have typed in JavaScript (no PHP).
I've tried Googling this fairly extensively but every result seems to find this behavior undesirable.
Edit: Not sure what I am doing wrong, this is what I tried:
<input id="myInput" type="text">
<script>
var myInput = document.getElementById("myInput");
if (sessionStorage.getItem("autosave"))
myInput.value = sessionStorage.getItem("autosave");
myInput.addEventListener("change", function() {
sessionStorage.setItem("autosave", myInput.value);
});
</script>
Edit (again): Got it working, thank you:
<input id="myInput" type="text">
<script>
var myInput = document.getElementById("myInput");
window.onload = function() {
if (sessionStorage.getItem("autosave"))
myInput.value = sessionStorage.getItem("autosave");
}
myInput.addEventListener("keyup", function() {
sessionStorage.setItem("autosave", myInput.value);
});
</script>