Do some task when user stop typing

Shared by: abdulmumin

javascript

1
let typingTimer; // Timer to track typing
2
const delay = 1000; // Adjust the delay as needed (in milliseconds)
3

4
// Function to handle text input
5
function handleAutoSave() {
6
    clearTimeout(typingTimer); // Clear the previous timer
7

8
    typingTimer = setTimeout(function () {
9
        // This function will run after the delay (user has stopped typing)
10
        save();
11
    }, delay);
12
}
13

14
// example
15

16
``` 
17
<input on:input={handleAutoSave} />
18
```
Love it? Share it!

DevCanvas DevCanvas Logo

Online Editor with a collection of awesome frontend code and code snippets for developers of all levels.

Legal & Support

Stand with Palestine 🇵🇸! DO NOT BE SILENCED

© 2025 DevCanvas. All rights reserved.