Answers for "javascript auto save input"

0

javascript auto save input

var saveTimeoutId;

document.addEventListener("DOMContentLoaded", () => {
  // Get the element(s) you want to autosave
  let area = document.getElementById('area');
  
  // use keyup over keypress so that backspaces will register
  area.addEventListener('keyup', () =>{
    
    // clear save timeout as the user is editing
    if (saveTimeoutId) window.clearTimeout(saveTimeoutId);
    
    // Store the timeout id again
    saveTimeoutId = window.setTimeout(() =>{
      ...
      // Code for saving here
      ...
    }, 1000); // Configure timeout period to preference
  });
  
});
Posted by: Guest on July-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language