Autocomplete pageup/pagedown key events

Autocomplete pageup/pagedown key events

I have an autosuggest feature where i want to enable key functionality to scroll up and down through the dropdown list. heres my code

  1. $(document).ready(function() {
  2.   $('.dropdown').hide();
  3.     $('.autosuggest').keyup(function (e) {
  4.       isDelete = false;
  5. // if delete or backspace were pressed,
  6. // less than 3 characters also trigger suggestion
  7.         if( e.which == 8 || e.which == 46) {
  8.              isDelete = true;;
  9.           }
  10. var search_term = $(this).attr('value');
  11.   if(
  12.      search_term.length == 0 ||
    1. (search_term.length < 1 && isDelete == false)
    2. ) {
      1. $('.dropdown').hide();
    3. } else {
      1. $('.dropdown').show();
    4. }

    1. if(search_term.length >= 1 || isDelete == true) {
      1. var category=$('#category').attr('value');
      1. var conditions = {
      2. 'search_term' : search_term,
      3. 'category' : category
      4. };

    1. $.post('ajax/searchApp.php', conditions, function(data) {
    2. $('.result').html(data);
      1. $('.result li').click(function() {
      2. var result_value=$(this).text(); 
        1. $('.autosuggest').attr('value',result_value);
        2. //alert(result_value);
        3. $('.result').html('');
        4. });
        1. });
      1. };
      2. });
    1. $('result').keydown(function(e){
    2.     if (e.keyCode == 38) {
    3. $(this).prev().focus(); 
    4.     }else if (e.keyCode == 40) {
    5. $(this).next().focus(); 
    6.     }
    7.     });
    8. });