IgorKorytin

Untitled

Sep 11th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1.     <script>
  2.         let ds = document.forms[0];
  3.         ds.onchange = () => {
  4.             let json = JSON.stringify(Array.from(new FormData(ds)));
  5.             localStorage.setItem(ds.id, json);
  6.         };
  7.         document.addEventListener("DOMContentLoaded", () => {
  8.             let values = JSON.parse(localStorage.getItem(ds.id));
  9.             for (let i = 0; i < values.length; ++i) {
  10.                 let el = ds[values[i][0]];
  11.                 if (el.type === "checkbox")
  12.                     el.setAttribute("checked", "");
  13.                 else
  14.                     el.value = values[i][1];
  15.             }
  16.         });
  17.     </script>
Advertisement
Add Comment
Please, Sign In to add comment