Created
August 29, 2019 02:31
-
-
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
This file contains 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
// 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