Skip to content
Related Articles
Open in App
Not now

Related Articles

How to create dynamic autocomplete search using Bootstrap Typeahead ?

Improve Article
Save Article
Like Article
  • Last Updated : 14 Jul, 2021
Improve Article
Save Article
Like Article

In this article, we will learn to implement dynamic autocomplete search using Bootstrap Typeahead. Bootstrap Typeahead is a plugin that helps to add a beautiful autocomplete option in the search bar. 

In this approach, we will be taking static data for autocomplete, but we can also use dynamic JSON data as well, to show search options. The methods used in the Typeahead plugin are as follows.

  • .typeahead(options): Initializes an input with a typeahead.
  • .lookup: To trigger the lookup function externally.
  • .getActive: To get the currently active item, you will get a string or a JSON object depending on how you initialized typeahead. It works only for the first match.

Example: The following example demonstrates the dynamic autocomplete search using Bootstrap Typehead.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0" />
    <script src=
    <script src=
    <link href=
        rel="stylesheet" />
        .typeahead {
            width: 50%;
            top: 60px !important;
            left: 50px !important;
<body style="text-align: center">
        <b><p>Suggest the states of India</p></b>
        <input type="text" class="typeahead" 
            placeholder="Enter name of states of India " />
        // Initializes  input( name of states)
        // with a typeahead
        var $input = $(".typeahead");
            source: [
                "Andhra Pradesh",
                "Arunachal Pradesh",
                "Himachal Pradesh",
                "Madhya Pradesh",
                "Tamil Nadu",
                "Uttar Pradesh",
                "West Bengal",
            autoSelect: true,
        $input.change(function () {
            var current = $input.typeahead("getActive");
            matches = [];
            if (current) {
                // Some item from your input matches
                // with entered data
                if ( == $input.val()) {


dynamix automatic typeahead

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!