Skip to content

Instantly share code, notes, and snippets.

@allanortiz
Created May 11, 2016 16:10
Show Gist options
  • Select an option

  • Save allanortiz/dce3a071c0cc0a77f2d269995b045d13 to your computer and use it in GitHub Desktop.

Select an option

Save allanortiz/dce3a071c0cc0a77f2d269995b045d13 to your computer and use it in GitHub Desktop.

Revisions

  1. allanortiz created this gist May 11, 2016.
    20 changes: 20 additions & 0 deletions search-after-typing.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    //setup before functions
    var typingTimer; //timer identifier
    var doneTypingInterval = 5000; //time in ms, 5 second for example
    var $input = $('#myInput');

    //on keyup, start the countdown
    $input.on('keyup', function () {
    clearTimeout(typingTimer);
    typingTimer = setTimeout(doneTyping, doneTypingInterval);
    });

    //on keydown, clear the countdown
    $input.on('keydown', function () {
    clearTimeout(typingTimer);
    });

    //user is "finished typing," do something
    function doneTyping () {
    //do something
    }