keypress event in autocomplete jquery ui
Asked Answered
T

1

7

I want to show the value of the autocomplete suggesion on textbox only when the user is selecting the suggession. I tried

$("#trainerNameAutoComplete").autocomplete({
    source:"serverpage.php?id="+1,
    minLength:1,
    focus: function( event, ui ){
        $("#trainerNameAutoComplete").val('');
    },
    keypress: function(event,ui){
        if ((event.which == 38||event.Keycode ==38) || (event.which == 40||event.Keycode ==40)) {
            console.log("key down");
            $("#trainerNameAutoComplete").val('');
        }
    },
    select:function(event,ui){
        somefunction();
    }
});

but the value is cleared in textbox when I hover the mouse over the suggestion but not when I press up and down arrow keys.

Tamalatamale answered 28/2, 2013 at 14:18 Comment(0)
C
1
 keydown: function(event,ui){
        event.preventDefault();
        if (event.Keycode ==38||event.Keycode ==40) {
            console.log("key down");
            $("#trainerNameAutoComplete").val('');
        }
    },

try this..instead of your keypress event

Cloudlet answered 28/2, 2013 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.