javascript
Run a Javascript function after user finished writing in the input field
The code can be used to run a function when the user finished writing in javascript.
var type_timer;
var finished_writing_interval = 3000;
var my_input = document.getElementById("my_input");
//Start timeout when user start typing
my_input.addEventListener('keyup', function () {
clearTimeout(type_timer);
type_timer = setTimeout(finished_typing, finished_writing_interval);
});
//Clear timeout on key down event
my_input.addEventListener('keydown', function () {
clearTimeout(type_timer);
});
//This function runs when user has finished writing in input
function finished_typing () {
console.log("User finished typing");
//Do something here ...
}
Was this helpful?
Similar Posts
- Javascript to run a function after script file is loaded
- jQuery code to run a function after page load
- Remember previously entered data in an input field using local storage in Javascript
- Radio Button Input field in Redux Form
- Run a function every 5 seconds interval using Javascript
- Pass a function as parameter of another function in Javascript
- Run a Javascript file in Terminal window