Reputation: 21
I want to display the autocomplete list triggered by the focus() event, but looks like it only works for the first time when i focus on the "id" text box, and then i focus on the "id2" textbox, and focus back on "id" textbox, my autocomplete list will not be displayed, any reason why?
<link media="all" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$('#id').autocomplete({
source: ["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
],
minLength: 0
});
$('#id').focus(function(){
$(this).trigger('keydown.autocomplete');
});
});
</script>
<input type="text" id="id">
<input type="text1" id="id2">
I want to display the autocomplete list triggered by the focus() event, but looks like it only works for the first time when i focus on the "id" text box, and then i focus on the "id2" textbox, and focus back on "id" textbox, my autocomplete list will not be displayed, any reason why?
<script type="text/javascript">
$(function() {
$('#id').autocomplete({
source: ["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
],
minLength: 0
});
$('#id').focus(function(){
$(this).trigger('keydown.autocomplete');
});
});
Upvotes: 2
Views: 2739
Reputation: 1
Try using
$(this).autocomplete("search",$(this).val())
instead of
$(this).autocomplete("search")
and make
minLength: 1
Upvotes: 0
Reputation: 4354
Do it this way
<script type="text/javascript">
$(function() {
$('#id').autocomplete({
source: ["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
],
minLength: 0
}).on("focus", function () {
$(this).autocomplete("search", '');
});
});
</script>
Upvotes: 0
Reputation: 145
Try using
$(this).autocomplete("search")
instead of
$(this).trigger('keydown.autocomplete')
Upvotes: 3