Skip to content

Instantly share code, notes, and snippets.

@dkordik
Created June 28, 2011 20:52
Show Gist options
  • Save dkordik/1052176 to your computer and use it in GitHub Desktop.
Save dkordik/1052176 to your computer and use it in GitHub Desktop.
Automatically save and repopulate input values across the current session using sessionStorage
(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