title: Execute function when a user has entered more than 5 characters in text box
body: <p>I am trying to run a jQuery function when a user types in more than 5 characters in a text box. So far I've managed to get my script to run using the keyup function, however this causes the script to run the moment the user types in the very first character and I only want it to run when the user has typed in 5 or more characters.</p>
  
  <p>Here's my code, I'm brand new to jquery so would really appreciate it if someone could please show me where I am going wrong with this. thanks in advance,</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function() {
          //alert('Document is ready');
          $('#search').keyup(function() {
              if ($("#search").val().length &gt; 3)
                  var sel_stud = $(this).val();
                  //alert('You picked: ' + sel_stud);
  
                  $.ajax({
                      type: "POST",
                      url: "include/fetch_search.php",
                      data: 'theOption=' + sel_stud,
                      success: function(whatigot) {
                          //alert('Server-side response: ' + whatigot);
                          $('#search_results').html(whatigot);
                          $('#theButton').click(function() {
                          alert('You clicked the button');
                      });
                  } //END success fn
              }); //END $.ajax
          })}; //END dropdown change event
      }); //END document.ready
  &lt;/script&gt;
  </code></pre>