Luis Gouveia
Luis Gouveia

Reputation: 8925

Show dropdownlist with JQuery Autocomplete suggestions

My JQuery autocomplete is working almost fine. After inserting "Af", if I press KeyDown, I correctly get "Afghanistan". However, I can never see the dropdownlist with all the countries. Am I missing some autocomplete option?

My Code:

@Html.TextBox("Countries", "", new { @class = "COUNTRIES", @placeholder = "Insert Country..."}) 

<script src="https://code.jquery.com/jquery-1.9.1.js"></script>

<script>
    $(function () {
        var countriesList = ["Afghanistan", "Albania", "Algeria"]
        $(".COUNTRIES").autocomplete({ source: countriesList });
    });
</script>

Upvotes: 1

Views: 35916

Answers (2)

Daniel Melo
Daniel Melo

Reputation: 558

This example is from jquery site

  $( function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
 
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
   
  
<html>  
<body>
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
</body>
</html>

Upvotes: 4

Yt Li
Yt Li

Reputation: 61

You can see this example in http://www.encodedna.com/2013/08/jquery-autocomplete-dropdown-list-on-focus.htm.

It shows the drop down list when focusing on the input by adding

.focus(function() {$(this).autocomplete("search", "");})

And you also can set the scroll style.

 

Upvotes: 6

Related Questions