前提
初心者です。input要素にある値すべてを保存して、ページ読込の際に
全て表示されるようにしたいのですが、詰まってしまいましたのでご教授いただければ幸いです。
実現したいこと
一時保存ボタンを押下時、値を保存する。
確定をtrueにするまで、再度画面を開いても保存した各値を表示させるようにする。
発生している問題・エラーメッセージ
保存ができない状態
Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)
該当のソースコード
ソースコード <script type="text/javascript"> // 一時保存 function save() { let new_data = document.getElementById("inp").value; if(localStorage.getItem('data') == null) { localStorage.setItem('data', '[]'); } let old_data = JSON.parse(localStorage.getItem('data')); old_data.push(new_data); localStorage.setItem('data', JSON.stringify(old_data)); } function Load() { document.getElementById("inp").value = localStorage.getItem("text"); } html <body onLoad="Load();"> <form> <input type="reset" value="リセット"> <input type="button" value="行新規" id="add"> <input type="button" id="copy" value="行複製"> <input type="button" value="一時保存" onclick="save()"> <input type="button" value="確定" onclick="confirm('本当に確定しますか')"> <table id="tbl"> <thead class="thead-light"> <tr> <th class="th-width">氏名</th> <th class="th-width">担当地区</th> <th class="th-width">売上</th> <th class="th-width">保有顧客数</th> <th class="th-width">課</th> <th></th> </tr> </thead> <tbody id="data"> <tr id="tr1" th:each="dw, stat : ${division}" th:object="${editForm}"> <td><input type="text" name="user_name" id="inp"></td> <td><input type="text" name="place" id="inp"></td> <td><input type="text" name="sale" id="inp"></td> <td><input type="text" name="customer" id="inp"></td> <td><input type="text" name="division_name" id="inp"></td> <td><input type="button" value="削除" onclick="del()"></td> </tr> </tbody> </table> </form>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。