title: AJAX: Arrow Up and Down is not working in suggested drop down list
body: <p>I have already created an auto-suggest box using AJAX and jQuery with PHP and postgreSQL with some help. I am still very new to AJAX and still learning the code as I go along.  Luckily, the auto-suggest is working great, but I noticed that my up and down cursor keys for the keyboard are not working at all. Nothing happens when I arrow up or down in the suggested list.  I am able to use the mouse to select in the suggested list, but cannot select things by use of keyboard arrows.  What I want to do is change the keyup to keydown or add the keydown somewhere so this way it can go cross browser, and then move the selection in the required direction based on the keyCode.  However I am still new to AJAX, and everytime I tried coding it, the suggested drop down list stops working or just crashes the page. I know it is in my ajax portion of the script.  Shouldn't have anything much to do with the HTML or my php page.  Any help getting the arrow keys to work along with the mouse is appreciated.  Any code examples will be appreciated as well.    </p>
  
  <pre><code>$(document).ready(function(){
      $("#search-box").keyup(function(){
          $.ajax({
              type: "POST",
              url: "autocomplete.php",
              data: 'keyword=' + $(this).val(),
              beforeSend: function() {
                  $("#search-box").css("background", "#FFF url(LoaderIcon.gif) no-repeat 165px");
              },
              success: function(data){
                  $("#suggesstion-box").show();
                  $("#suggesstion-box").html(data);
                  $("#search-box").css("background", "#FFF");
              }
          });
      });
  });
  
  function selectCountry(val) {
      $("#search-id").val(val);
      $("#suggesstion-box").hide();
  }
  
  function updateSearchBox(el) {
      $("#search-box").val($(el).html());   
  }
  </code></pre>
  
  <p>Here is the HTML code for the search input in the form:</p>
  
  <pre><code>&lt;div style="background-color:#ffffff; width:100%; float:left;  padding-bottom:25px; clear:both;  "&gt;
      &lt;div class="frmSearch " style="width:90%; float:left;"   &gt;
          &lt;label&gt;                                             
              &lt;input maxlength="75" type="search" name="jurisdiction_search"  class="search_keyword" id="search-box" placeholder="Enter County, City, or Client Name"  /&gt;
              &lt;input type="hidden" name="search" id="search-id"  /&gt;
              &lt;div class="box" id="suggesstion-box"&gt;&lt;/div&gt;
          &lt;/label&gt;                                                
      &lt;/div&gt;
      &lt;div style="width:10%; float:left; clear:right;"&gt;
          &lt;label&gt;                                         
              &lt;input style="width:100%; height: 50px; " type="submit"  value="&lt;?php echo esc_attr_x( 'Search', 'submit button' ) ?&gt;" /&gt;
          &lt;/label&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is some of the code in the autocomplete.php</p>
  
  <pre><code>&lt;?php
  if (!$result){
      echo "&lt;div class='show' align='left'&gt;No matching records.&lt;/div&gt;";
  }else {
  ?&gt;
      &lt;ul id="country-list" &gt;
          &lt;?php
          while($row=pg_fetch_assoc($result)){
          ?&gt;                                      
              &lt;li  onClick="selectCountry('&lt;?php echo $row["id"]; ?&gt;'); updateSearchBox(this);"&gt; &lt;?php echo "(".$row["id"].") ".$row["company"].", ".$row["st"]; ?&gt; &lt;/li&gt;
          &lt;?php } ?&gt;
      &lt;/ul&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>Here is my last failed attempt at working with ajax to get the arrow keys to work.  Like I mention above, the suggested box stop working on this attempt.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      $(document).on("keydown", function(e) {
          if (e.keyCode == 40) {
               if(chosen === "") {
                   chosen = 0;
               } else if((chosen+1) &lt; $('#search-box').length) {
                  chosen++;
               }
                $('#search-box').removeClass('selectedhash');
                $('#search-box:eq('+chosen+')').addClass('selectedhash');
  
                 return false;
          }
          if (e.keyCode == 38) {
              if(chosen === "") {
                  chosen = 0;
              } else if(chosen &gt; 0) {
                  chosen--;            
              }
              $('#search-box).removeClass('selectedhash');
              $('#search-box:eq('+chosen+')').addClass('selectedhash');
               return false;
  
          }
      });
  
  
      $("#search-box").live("keyup",function(e){
          $.ajax({
          type: "POST",
          url: "/VCSWeb/wp-content/themes/i-excel-child/autocomplete.php",
          data:'keyword='+$(this).val(),
          beforeSend: function(){
              $("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
          },
          success: function(data){
              $("#suggesstion-box ").show();
              $("#suggesstion-box").html(data);
              $("#search-box").css("background","#FFF");
          }
          });
      });
  });
  
  function selectCountry(val) {
    $("#search-id").val(val);
    $("#suggesstion-box").hide();
  }
  
  function updateSearchBox(el) {
    $("#search-box").val($(el).html());   
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Again, very new to AJax and any help will be greatly appreciated.  </p>