Saving forms

  1. Set the localStorage key to be the current URL.
  2. If there’s already an entry for the current URL, update the textarea with the value in localStorage.
  3. Write a function to store the contents of the textarea in localStorage but don’t call the function yet.
  4. The first time that a key is pressed inside the textarea, start listening for the page being unloaded.
  5. When the page is being unloaded, invoke that function that stores the contents of the textarea in localStorage.
  6. When the form is submitted, remove the entry in localStorage for the current URL.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Keith

Jeremy Keith

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com