Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<script type="text/javascript" language="javascript">
    $(function () {
        $('#<%=txtItemCode.ClientID %>').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "WebService.asmx/GetItemCode",
                    data: "{ 'ItemCode': '" + request.term + "' }",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function (result) {
                        response(result.d);
                    },
                    error: function (result) {
                        alert('There is a problem processing your request');
                    }
                });
            },
            minLength: 0
        focus: function (event, ui) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: "{ Iid: '" + $('#<%=txtItemCode.ClientID %>').val() + "'}",
                url: "WebService.asmx/GetNameFromService",
                dataType: "json",
                success: function (data) {
                    $('#<%=txtKeyWord.ClientID %>').val(data.d);
                }
            });
        }
    });

</script>


I have the above script which has auto complete for textbox.Event should be raised when user clicks from the autocomplete.

I got an error near 'focus function' I tried maximum to get rid of that error its just not working.Pls help me.Probably im missing one of these },}),please tell me where to close .
Posted

1 solution

Correct the following.

1. Missing Comma after minLength
2. Missing ending brackets of $(function ().

So, code would look like...
XML
<script type="text/javascript" language="javascript">
    $(function () {
        $('#<%=txtItemCode.ClientID %>').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "WebService.asmx/GetItemCode",
                    data: "{ 'ItemCode': '" + request.term + "' }",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function (result) {
                        response(result.d);
                    },
                    error: function (result) {
                        alert('There is a problem processing your request');
                    }
                });
            },
            minLength: 0, // Missing Comma
            focus: function (event, ui) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: "{ Iid: '" + $('#<%=txtItemCode.ClientID %>').val() + "'}",
                    url: "WebService.asmx/GetNameFromService",
                    dataType: "json",
                    success: function (data) {
                        $('#<%=txtKeyWord.ClientID %>').val(data.d);
                    }
                });
             }
        });
    }); // Missing ending brackets of $(function ().
</script>
 
Share this answer
 
v2
Comments
Challa92 12-Feb-14 0:57am    
thanks so much!

i still have problem though..the mouseover function is not being raised how do i do it?
Autocomplete works only when you write something, it matches with the data and shows you suggestions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900