Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Created August 29, 2019 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcrampton/c0e60b25e0edaf57135e65054786ce6d to your computer and use it in GitHub Desktop.
Save adamcrampton/c0e60b25e0edaf57135e65054786ce6d to your computer and use it in GitHub Desktop.
Set a jQuery element's value using a specified key in local storage
// Fetch storage item if it exists and set element value
function updateFieldValueFromStorage(elementId, storageKey) {
let storage = window.localStorage;
if (storage.getItem(storageKey)) {
($('#' + elementId).val(storage.getItem(storageKey)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment