javascript - To Do List using JQuery and LocalStorage -


hi guys i'm trying create todo list using jquery , local storage.

  1. if localstorage has values already, should populate when page loads (closing window , reopening retains "todo's")
  2. if item exists in list, show console message noting duplicate (using $.inarray)
  3. user should able add , remove items , have changes save automatically (using splice)

this have far:

<body>   <h1>todo list</h1>   <input id="input" type="text"><button id="add">add</button>   <ul id="list"></ul> </body>  <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script> <script> if(window.localstorage !== undefined){ var storedata = { }; var input = $("#input").val(); $("#add").click(function (){   localstorage.setitem("input", json.stringify(input)); }); };  $(document).ready(function(){   var data = json.parse(localstorage.getitem("storedata"));   $("#list").html(data); }); </script> 

is wrong in code? how can add splice , check duplicates using $.inarray? thanks.

you setting 1 key input , retrieving different key storedata

try changing

localstorage.setitem("input", json.stringify(input)); 

to

localstorage.setitem("storedata", json.stringify(input)); 

if trying store array need rethink add functionality. right store value of input when page loads...which empty. , have no array work in code

i suggest @ code used in todomvc


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -