function addMsg() { let doc = document, msgName, msgDesc, msgDate, html; if (doc.getElementById('name').value) { msgName = doc.getElementById('name').value; } else { doc.getElementById('name').focus(); return; } if (doc.getElementById('desc').value) { msgDesc = doc.getElementById('desc').value } else { doc.getElementById('desc').focus(); return; } msgDate = doc.getElementById('date').value = new Date(); html = '<section class="msg"><div><span>By ' + msgName + '</span><span>' + msgDate + '</span></div> <p>' + msgDesc + '</p></section>'; let test = { name: msgName, desc: msgDesc, date: msgDate } localStorage.setItem('test', JSON.stringify(test)); //if (doc.getElementById('result').innerHTML += html) doc.forms.myform.reset(); let testMSG = JSON.parse(localStorage.getItem("test")); if (doc.getElementById('testMSG').innerHTML += html) doc.forms.myform.reset(); } input, textarea { width: 100%; box-sizing: border-box; } section { background: #e9e9e9; border: 1px solid #ccc; width: 320px; margin: 3px; } p { border: 1px solid #666; margin: 3px; padding: 5px; font-size: 14px; } span { font-size: 12px; margin: 5px; } <aside class="right" id="testMSG"> </aside> <!-- form msg comm --> <section class="form-box"> <form id="myform" action=""> <input id="name" value="" placeholder="Type your nickname here..." name="login" > <textarea id="desc" placeholder="Write your comment here..." name="msg"></textarea> <input id="date" type="hidden" /> <input value="OK" type="button" onclick="addMsg()" /> </form> </section> Good day! I tried to master the possibilities of localStorage for myself, the record goes perfectly well. But after reloading the page, the data is not saved. Tell me what's wrong.
Thank you in advance!
var test = JSON.parse(Localstorage.test). Because You try to master LocalStorage - I will not write code. Try, for a start, for yourself - Dmytryk