Skip to content Skip to sidebar Skip to footer

How To Implement Local Storage On Html?

(Updated)Here is the View Source. For Example: You have a list of Names..I have to use a foreach loop because are over 100 names. And once the user selects the name, I have there

Solution 1:

Instead of doing it in the server side, use the client side to make it possible.

functionupdateSelection(which) {
  if (typeoflocalStorage != "undefined")
    localStorage.setItem("select", which.value);
}
window.onload = function () {
  if (typeoflocalStorage != "undefined")
    document.querySelector("#sel").value = localStorage["select"];
};
<selectid="sel"onchange="updateSelection(this);"><optionvalue="1">Option 1</option><optionvalue="2">Option 2</option><optionvalue="3">Option 3</option><optionvalue="4">Option 4</option><optionvalue="5">Option 5</option></select>

If the Stack Snippets are sandboxed, see the live preview at JSBin.

Post a Comment for "How To Implement Local Storage On Html?"