How To Create Dropdown With Search

Nowadays, a search is a very helpful material in terms of searching on the internet. Also, it is very useful feature for the HTML source code in the function of a simple dropdown. This is a user-friendly kind of function. In this tutorial, we are going learn about on How to Create Dropdown with Search with the help of jQuery script. With the use of this script, the simple dropdown will expand the function to be a searchable tool. We are going to list new movies in 2016 in the (select) element of dropdown with a search. There’s a lot of movies, we only have 10 to 15 example but you can edit after you download the source code.

Dropdown with Search

This source code composes of (select) element insert by the id attribute.
  1. <!DOCTYPE html>
  2.  
  3. How to Create Dropdown with Search
  4. </title>
  5. <javascript><script src="js/code_js1.js" type="text/javascript"></script>
  6.  
  7. <script src="js/code_js.js"></script>
  8.  
  9. <script type="text/javascript">
  10. $(document).ready(function() {
  11. var new_movies = ["God's Not Dead 2", "Captain America: Civil War", "Love Games", "The Huntsman: Winter's War", "The Jungle Book", "Ki & Ka",
  12. "Meet the Blacks", "Rocky Handsome", "Kapoor and Sons", "Miracles from Heaven", "Eye in the Sky",
  13. "Zootopia", "I Saw the Light", "London Has Fallen", "Divergent Series: Allegiant"];
  14. $("#new_movies").select2({
  15. data: new_movies
  16. });
  17. });
  18. </script><javascript>
  19.  
  20. <link href="css/code_css.css" rel="stylesheet" />
  21. </head>
  22.  
  23. <h1>How to Create Dropdown with Search</h1>
  24. <div>
  25. <select id="new_movies" style="width:300px;"></select>
  26. </div>
  27.  
  28. </body>
  29.  
  30. </html>
This is a static data and we can also get the data into the database to become dynamic. There are many features for dropdown list search and you can add after you download the source code below. Share us your thoughts and comments below. Thank you so much for dropping by and reading this blog post. For more updates, don’t hesitate and feel free to visit our website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you.

Add new comment