Q:

Toggle up/down with up down keys in auto suggest

I am trying to make auto-suggest using ajax with php and mysql. Auto-suggest is working well but I am getting problem with toggling up down with up down keys. I am following this jsfiddle as example for completing my work. But can't get why Navigate function is been called twice. Because it alerts twice when I press down keys.
jquery
 var Navigate = function(diff){

 displayBoxIndex += diff;

    var oBoxCollection = $("#searched a .searchFull");

    if (displayBoxIndex >= oBoxCollection.length) {
        displayBoxIndex = 0;
        alert("A");
    }
    if (displayBoxIndex < 0) {
        displayBoxIndex = oBoxCollection.length - 1;
        alert("B");
    }
    var cssClass = "selected";
    oBoxCollection.removeClass(cssClass).eq(displayBoxIndex).addClass(cssClass);

}
$(document).on('keypress keyup', "#search", function (e) {
    if (e.keyCode == 13 || e.keyCode == 32) {
        $('.display_box_hover').trigger('click');
        return false;
    }
    if (e.keyCode == 40) {
        //down arrow
        Navigate(1);
    }
    if (e.keyCode == 38) {
        //up arrow
        Navigate(-1);
    }
});

HTML
 <div id="searched" style="display: block;">
   <a href="http://localhost/c2c/init/product/78">
      <div class="searchFull">
   </a>
   <a href="http://localhost/c2c/init/product/77">
      <div class="searchFull">
   </a>
   <a href="http://localhost/c2c/init/product/76">
      <div class="searchFull">
   </a>
   <a href="http://localhost/c2c/init/product/73">
      <div class="searchFull">
   </a>

A:

Here is the solution for your issue:
You call two events like: keypress and keyup. So, it will call twice. 
Just remove one like here i remove keypress and here it works well.
$(document).on('keyup', function (e) {
        if (e.keyCode == 13 || e.keyCode == 32) {
            $('.display_box_hover').trigger('click');
            return false;
        }
        if (e.keyCode == 40) {
            //down arrow
            //alert("down");
            Navigate(1);
        }
        if (e.keyCode == 38) {
            //up arrow
            Navigate(-1);
        }
    });

Check Fiddle here.
And as per comment Here selected class not removed checked in firebug. See below image.

Hope it helps.

