jquery - How to display saved localStorage data when a button is click? -


good evening, i'm amateur programmer trying make simple jqm web apps. have made full crud , got save form local storage. problem i'm having displaying it. display home page; under , when save button clicked. how go doing that? i'm stuck.

<!--home page-->  <section data-role="page" id="home">     <header data-role="header">         <h1>counter</h1>     </header>      <section>        </section>      <footer data-role="footer" data-position="fixed">         <nav data-role="navbar">             <ul>                 <li><a href="#home"></a></li>                 <li><a href="#display"></a></li>                 <li><a href="#app"></a></li>             </ul>         </nav>     </footer> </section> 

heres js.

  //store data function      var storedata = function(key){  var id = math.floor(math.random()*10000001);      var item= {};         item.name=      ["name:", $("#name").val()];         item.category=      ["type:", $("#category").val()];         item.fav=   ["favorite:", $("#fav").val()];         item.comments=      ["comments:", $("#comments").val()];         localstorage.setitem(id, json.stringify(item));         alert("saved!");         $.mobile.changepage("#add"); 

};

you can access storage data window.localstorage['key']. example, if saved name, birthday , gender locale storage can retrieve them with:

var name = window.localstorage['name']; var birthday = window.localstorage['birthday']; var gender = window.localstorage['gender']; 

then can use javascript load them elements:

document.getelementbyid('name-div').innertext = name ... 

of course assuming have proper html divs in place:

<div id="name-div"></div> 

and on. you're looking for?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -