How to use Javascript localStorage to retain values of HTML input elements on Page Refresh?
How to use Javascript localStorage to retain values of HTML input elements on Page Refresh? localStorage in Javascript is used to retain the values of the HTML input elements on the page refresh. setItem() and getItem() methods are used to set and get the data from the localStorage. clear() method is used to clear the data from the localStorage. Suppose I have following 2 textboxes and buttons in my HTML page. <input type="text" id="text1" value="" /> <button type="button" id="myButton1" onclick="myButtonClicked('text1')">Click Me</button> <input type="text" id="text2" value="" /> <button type="button" id="myButton2" onclick="myButtonClicked('text2')">Click Me</button> I fill some data in each textbox. Now when I refresh the page, the data is lost. I want to retain that data on the page refresh. I will use localStor...