Keypress event in jquery ui autocomplete

I want to show the value of an autocomplete sentence in a text box only when the user selects a sentence. 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 the text box when I hover over this sentence, but I donโ€™t press the up and down arrow keys.

+7
source share
1 answer
  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

+1
source

All Articles