Skip to content

Instantly share code, notes, and snippets.

View rosemulazada's full-sized avatar

Rose Mulazada rosemulazada

  • Amsterdam Academy of Applied Sciences
  • The Netherlands
  • 18:40 (UTC +02:00)
  • LinkedIn in/rose-mulazada-6664a2254
View GitHub Profile
@rosemulazada
rosemulazada / script.js
Last active April 7, 2024 05:32
SCALABLE: Save form data to localStorage and auto-complete on refresh
// With the help of Jeremy Keith, I was able to create a fully scalable code sample that you can copy-paste into your project.
// It will save the user input value on blur, this includes radio buttons, checkboxes and date inputs besides regular text/number inputs.
// The only condition is that you give the form element on your page a data-attribute of data-form-topic="foo".
// This code snippet saves the data-attribute as the key to the localStorage, and the value of it will be an object with key/value pairs of the respective inputs name and value.
// Please refer to this gist somewhere in your code if you use it :)
// Happy coding!
// VARIABLE DECLARATIONS
// objects
let savedData = {};