Sindhu Yadav

Sindhu Yadav

  • NA
  • 11
  • 6.6k

search box functionality in ajax jquery

Jan 2 2015 2:48 AM
Hi,
If i search a letter in 'Search Box' for example 'a', 'a' related wordings should come in drop down with hyperlink. Data should fetch from database. I have created database for this search box and stored all 'a' related wording in the database.
Now its displaying the 'a' related Items in the drop down list without any link. Now I am able to get only the first element from drop down list. But i would like to get and access selected item
(using mouse or keyboard) from the list instead of the first item. Please suggest an answer.

The dropdown is from jQuery UI.
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js

Here is the part of the jquery code where I am accessing the first element from the list using data.d[0]. 

Code:

<script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });
    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "../WFMTransaction/newf.aspx/GetAutoCompleteData",
                    data: "{'form_name':'" + document.getElementById('txtSearch').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response(data.d)
                        document.getElementById("Button1").href = data.d[0];
                        document.getElementById("Button1").text = data.d[0];

                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
            },
        });
    }
</script>




Answers (2)