Trigger keypress with jQuery

I did my homework and checked many questions, but still could not find something that I could get to work.

I have an input to search. When a user clicks, for example, I want the word "doctor" to be written in my letter-entry letter. I could do this by changing $ ("# search"). Val () is long, but here is the problem. When user input is usually entered into the search input, an autocomplete div appears. This is triggered by the keydown event. If I just changed the val attribute for the input, the autocomplete div will not work out, so I need to somehow trigger the keydown event to get it.

I found this solution:

$("#example").click(function() {    
    $("#search").focus();
    var e = jQuery.Event("keyup");
    e.keyCode = 50;                     
    $("#search").trigger(e);                    
});

but I could not get it to work. Any ideas please?

This is what html looks like:

<input type="text" id="search" />
Example: <span id="example">doctor</span>
+5
2
$("#example").click(function() {    
    $("#search").focus();
    var e = jQuery.Event("keydown");
    e.keyCode = 50;                     
    $("#search").trigger(e);                    
});

ref: jQuery

+8

textChange, keyup/down. $("#search").val() , .

: textChange, , .. ( )

0

All Articles