Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- let ds = document.forms[0];
- ds.onchange = () => {
- let json = JSON.stringify(Array.from(new FormData(ds)));
- localStorage.setItem(ds.id, json);
- };
- document.addEventListener("DOMContentLoaded", () => {
- let values = JSON.parse(localStorage.getItem(ds.id));
- for (let i = 0; i < values.length; ++i) {
- let el = ds[values[i][0]];
- if (el.type === "checkbox")
- el.setAttribute("checked", "");
- else
- el.value = values[i][1];
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment