Autocomplete jQuery TextBox Dropdown Example

Today, We want to share with you Autocomplete jQuery TextBox Dropdown Example.
In this post we will show you Autocomplete TextBox in jQuery, hear for How To Create Autocomplete on an Input Field we will give you demo and example for implement.
In this post, we will learn about javascript autocomplete textbox from array with an example.

Autocomplete jQuery TextBox Dropdown Example

There are the Following The simple About Autocomplete jQuery TextBox Dropdown Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop jQuery Autocomplete TextBox Dropdown Example, so the some major files and Directory structures for this example is following below.

  • index.html

How To Create Autocomplete on an Input Field

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

READ :  VueJS Two way data binding and state management components

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>jquery autocomplete multiple values</title>
    <link rel="stylesheet" type="text/css" href="https//www.pakainfo.com/css/smart-forms.css">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

    <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-custom.min.js"></script>

    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            var devlopers = [
                "AMIT",
                "JAYDEEP",
                "KRUNAL",
                "ANKIT",
                "CHIRAG",
                "NILESH",
                "MILAN",
                "VIVEK",
                "HITESH",
                "MAYUR",
                "RAVI",
                "VISHAL",
                "RAKESH",
                "VIJAY",
                "DINESH",
                "BHAVESH",
                "SUMIT",
                "JIGNESH",
                "JIGAR",
                "PRATIK",
                "VIDDHI",
                "NEHS",
                "KAJAL",
                "KRUPALI",
                "DIPTI",
                "DHARMESH",
                "MANSHI"
            ];

            $("#companyList").autocomplete({
                source: devlopers
            });

            var companyTags = [
                "MI",
                "APPLE",
                "LENOVO",
                "DELL",
                "PAKAINFO",
                "Arity",
                "MIT",
                "MANAGEENGINE",
                "Cloud",
                "INTEL",
                "OPPO",
                "SAMSUNG",
                "IPHONE",
                "ACER",
                "TVS",
                "MRF",
                "LG",
                "ONIDA",
                "NOKIA",
                "IDEA",
                "VODAPHONE",
                "BSNL"
            ];
            function split(val) {
                return val.split(/,\s*/);
            }
            function extractLast(term) {
                return split(term).pop();
            }
            $("#addmoreTags")
                .bind("keydown", function (event) {
                    if (event.keyCode === $.ui.keyCode.TAB &&
                        $(this).autocomplete("instance").menu.active) {
                        event.preventDefault();
                    }
                })
                .autocomplete({
                    minLength: 0,
                    source: function (request, response) {
                        response($.ui.autocomplete.filter(
                            companyTags, extractLast(request.term)));
                    },
                    focus: function () {
                        return false;
                    },
                    select: function (event, ui) {
                        var companyterms = split(this.value);
                        companyterms.pop();
                        companyterms.push(ui.item.value);
                        companyterms.push("");
                        this.value = companyterms.join(", ");
                        return false;
                    }
                });
        });
    </script>
</head>

<body>
    <h1>How To Create Autocomplete on an Input Field</h1>
    <div class="smart-wrap">
        <div class="smart-forms smart-container wrap-3">

            <div class="form-header header-success">
                <h4><i class="fa fa-pencil-square"></i> Autocomplete </h4>
            </div><!-- end .form-header card -->

            <form method="post" action="/" id="account2">
                <div class="form-body">

                    <div class="card">
                        <label for="companyList" class="field-label">Basic </label>
                        <label class="field">
                            <input type="text" name="companyList" id="companyList" class="gui-input" placeholder="Enter Company Name">
                        </label>
                    </div><!-- end card -->

                    <div class="card">
                        <label for="addmoreTags" class="pakainfo field-label">Select Multiple Items</label>
                        <label class="field">
                            <input type="text" name="addmoreTags" id="addmoreTags" class="gui-input" placeholder="Select multiple items">
                        </label>
                    </div><!-- end card -->

                </div><!-- end .form-body card -->
                <div class="form-footer">
                    <button type="submit" class="button btn-success"> Send Form </button>
                </div><!-- end .form-footer card -->
            </form>

        </div><!-- end .smart-forms card -->
    </div><!-- end .smart-wrap card -->
    <div></div><!-- end card -->
</body>
</html>

jQuery 15 Powerful Tips and Tricks for Developers and Web Designer

Read :

READ :  Angularjs Add class to Active Element ng-class Menu

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How To Create Autocomplete on an Input Field.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Add a Comment

Your email address will not be published. Required fields are marked *