Created
June 28, 2011 20:52
-
-
Save dkordik/1052176 to your computer and use it in GitHub Desktop.
Automatically save and repopulate input values across the current session using sessionStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
var $inputs = $("input"); //left as generic 'input' to acct for html5y types. | |
$inputs.each(function () { | |
if (this.value == '') { | |
this.value = sessionStorage["autosave-"+this.id]; | |
} | |
}) | |
$.fn.autosave = function () { | |
return this.each(function () { | |
console.log("attached autosave to ",this," for this session."); | |
$(this).keyup(function () { | |
sessionStorage["autosave-" + this.id] = this.value; | |
console.log("saved: ",this.value); | |
}); | |
}); | |
} | |
$inputs.autosave(); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment