javascript auto save input

Solutions on MaxInterview for javascript auto save input by the best coders in the world

showing results for - "javascript auto save input"
Abigail
23 Feb 2020
1var saveTimeoutId;
2
3document.addEventListener("DOMContentLoaded", () => {
4  // Get the element(s) you want to autosave
5  let area = document.getElementById('area');
6  
7  // use keyup over keypress so that backspaces will register
8  area.addEventListener('keyup', () =>{
9    
10    // clear save timeout as the user is editing
11    if (saveTimeoutId) window.clearTimeout(saveTimeoutId);
12    
13    // Store the timeout id again
14    saveTimeoutId = window.setTimeout(() =>{
15      ...
16      // Code for saving here
17      ...
18    }, 1000); // Configure timeout period to preference
19  });
20  
21});