Auto complete search textbox like google (multiple input & extra data)

I have posted another article like this.

But a different approach is used here. Previous article has single textbox with id selector and only the textbox text. But this time, we have multiple textboxes with class selectors and few extra data in the ajax request.

<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <title>AutoComplete Box with jQuery</title>
    <link href="" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
   <table data-employeeid="5">
       <tr data-id="546">
           <input type="text" class="suggestexam" />
        <tr data-educationid="103">
           <input type="text" class="suggestexam" />

//Put this code in head tag (placing this at the bottom of body tag may not work). 
    $(function () {
        $('body').on('focus', ".suggestexam", function () {
            var extra = $(this).closest('tr').attr("data-id");
                source: function (request, response) {
                        url: "/Employee/GetExamNameSuggestion",
                        data: JSON.stringify({ prefix: request.term, extradata: extra }),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        //dataFilter: function (data) { return data; },
                        success: function (data) {
                        error: function (XMLHttpRequest, textStatus, errorThrown) {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s