Show dropdownlist with JQuery Autocomplete suggestions
Solution 1
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>
Solution 2
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.
Luis Gouveia
Languages: Portuguese (Native), English (C2), French (C2), Spanish (B1) and Russian (A1) Technologies: Azure (SaaS, PaaS and IaaS), Azure Devops, C#, C++, C, ASP.NET Core, Azure Functions, ASP.NET MVC, Web Forms, Java, Entity Framework (Core), NHibernate, IIS, WCF, SOAP, REST, React, HTML5, CSS3, BootStrap, Javascript, jQuery, WEB API, Powershell, xUnit (Unit Tests), T-SQL, PL/SQL, Cosmos DB, Datalake, BlobStorage, Oracle, Azure SQL, SQL Server, SSRS, SSIS, TFS, GIT, SVN, JSON, OAuth, Docker, Kubernetes, Swagger, OData, Cloud Computing, Microservices, Serverless Architecture & CI/CD Pipelines. Methodologies: Scrum/Agile, Waterfall, TDD, DDD, KanBan, Lean, 5S Key Achievements: 2021 - Joins Microsoft! 2021 - Becomes Extia's .NET Architect in Portugal 2019 - Becomes the GFI's Service Center .NET Architect (supporting 20 .NET developers) 2019 - Awarded the GFI's Commitment Ambassador Prize (check photo in linkedin profile) 2019 - Wins the CityWay project for GFI 2018 - Presents the Application Services department (service-center) to the Minister of Economy and GFI's CEO (check photo in profile) 2018 - Wins 2 new projects for GFI: STACKR & ADP - Aéroports de Paris 2018 - ASP.NET MVC Core Master Class at ‘Instituto Politécnico de Setúbal’ (representing GFI) 2018 - Brings a new project from France for GFI's Service Center: STACKR, The insight maker 2017 – Less than 4 years after joining GFI, the turnover of his projects amount to more than 500.000 € 2017 – ASP.NET MVC Core Master Class at ‘Universidade Lusofona’ in Lisbon (representing GFI) 2016 – Project Manager/Tech Lead on “XPO Logistics”, a key client for the GFI’s service center 2016 – Project Manager/Tech Lead on “People Map” 2015 – Project Manager/Tech Lead on “Maxim: Maximus Inventory” 2014 – Team lead on “Pégase 3” 2014 - Hired by GFI as one of the founders of the GFI’s nearshore service center 2013 - Wise Waste TM gets CE certification 2013 - Wise Waste TM becomes the 1st product in Portugal with the following certification: “Common Criteria for Information Technology Security Evaluation” 2013 - 500th Wise Waste System is sold 2011, Valencia (ES) - Wise Waste wins 3rd prize for environ. innovation at EcoFira 2011, Lisbon (PT) - Wise Waste wins 2nd prize for environmental innovation (Environment Ministry) 2010 – Founds the ‘Muteco’ startup after creating an electrical bicycle on its own 2007 - Joins Auto-Sueco 2006 - Internship at CNRS (Centre National de la Recherche Scientifique) in Toulouse, France
Updated on July 06, 2022Comments
-
Luis Gouveia almost 2 years
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>
-
Dhaval Marthak almost 10 yearsYou're missing jQuery UI library to add!
-
Dhaval Marthak almost 10 yearsSee this! You must have to type something in textbox to make autocomplete work :)
-