title: How to use setTimeout / .delay() to wait for typing between characters
body: <p>I am creating a simple listbox filter that takes the user input and returns the matching results in a listbox via javascript/jquery (roughly 5000+ items in listbox). Here is the code snippet:</p>
  
  <pre><code>var Listbox1 = $('#Listbox1');
  var commands = document.getElementById('DatabaseCommandsHidden'); //using js for speed
  
  $('#CommandsFilter').bind('keyup', function() {
  
  Listbox1.children().remove();
  
  
  for (var i = 0; i &lt; commands.options.length; i++) {
      if (commands.options[i].text.toLowerCase().match($(this).val().toLowerCase())) {
          Listbox1.append($('&lt;option&gt;&lt;/option&gt;').val(i).html(commands.options[i].text));
      }
  }
  });
  </code></pre>
  
  <p>This works pretty well, but slows down somewhat when the 1st/2nd char's are being typed since there are so many items.</p>
  
  <p>I thought a solution I could use would be to add a delay to the textbox that prevents the 'keyup' event from being called until the user stops typing. The problem is, I'm not sure how to do that, or if its even a good idea or not.</p>
  
  <p>Any suggestions/help is greatly appreciated.</p>