how to make dropdown searchable in html using jquery

 how to make dropdown searchable in html using jquery


The search option in a list of HTML drop-downs is very useful! In particular it will enhance the convenience of the user to select the item from the drop-down containing the long list.

Searchable dropdown is very useful for the user because when there is a long list in the dropdown then it becomes easy for the user to select. In this post, we are going to list down the dropdown with a search option.

As a website developer, it is almost given that at some point you will work with HTML dropdown select, presenting the user with an array of options to select from.

 

This happens in the instances where you want the user to choose from already predefined answers/options instead of them entering their own.

 

This helps reduce redundancy in the system.

For instance, if you were to require the users to input their country, but let them type in the country name instead of selecting, this would create a disaster.

 

Let's say the user's country is USA. Some would write "United States of America", others "USA", others "United States", while others would misspell the name and write something totally different.

 

It would be a disaster trying to organize, analyze and present the information based on the users' country. This shows why HTML dropdown select is quite an important form element.

 

However, this comes with some complexities when the select options are too many. Locating the desired option could become a headache.

 

For this reason, having a search box within the dropdown select options is such an incredible and life-saving feature that can save a lot of time for many users.

 

Our Best Popular Projects & Posts

Post Link
School Management System With Full Source Code In php click here
ecommerce project in php click here
simple login and registration form in php click here
Synopsis for online rooms booking project based on PHP click here
add multiple images in codeigniter click here
beginners project in php with source code click here
dynamic country state dropdown in codeigniter click here
how to generate pdf using dompdf in codeigniter click here
add 1 day to current date in php click here
how to check website/blog responsive or not? click here
employee attendance management system project in php with source code click here
Select one checkbox and disable others click here
printing div content with css applied click here
best restaurants management system in php click here
Preview an image before it is uploaded using jquery click here
text editor in jquery click here
data table with export button in html click here
add multiple images in codeigniter click here
codeigniter some steps to install on Your server click here
ajax in php/codeigniter click here
Create Simple API CRUD with PHP and MySQL click here
How to integrate bootstrap theme in codeigniter click here
how to prepare for interview click here
Convert a date format in PHP click here
how to export html table to excel in jquery click here
how to create duplicate google peg using ajax click here
how to make dropdown searchable in html using jquery click here
how to find retirement date in php click here
online food order system in php with source code click here
school management project admin panel in php click here


 



coppy this code and paste on your html page

   <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
   <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
  <style type="text/css">
         .select2
  {
    width: 100%;
  }
  .select2-container .select2-selection--single {
    height: 38px!important;
    padding-top: 4px;
}
  </style>
 

                    <div class="form-group">
                        <label for="password" class="col-lg-4 control-label">Driver</label>
                        <div class="col-lg-8">

                            <select class="select2 form-control" name="driver_id" required>
                                <option value="">Select Driver</option>
                              <option>Value1</option>
                              <option>Value2</option>
                              <option>Value3</option>
                              <option>Value4</option>
                              
                                ?>
                            </select>
                        </div>
                    </div>
                    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
                    <script type="text/javascript">
    $('.select2').select2();
</script>

0 Comments