0

I have a text box which implements jquery autocomplete. I am using controller and action to load the auto complete. On selection of a value i want the value to be loaded to another textbox. I used select event but it is not giving me the result. I have attached my code snippet. kindly help me to resolve the issue

<script type="text/javascript">
$(document).ready(function () {
        $("#customer").autocomplete('/UserAdd/ClientList',
        {
            dataType: 'json',
            parse: function (data) {
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i],value: data[i].AccountNumber, result: data[i].Name };
                }
                return rows;
            },
            formatItem: function (row, i, max) {
                return row.Name;
            },
            select: function (event, ui) {
                $('#ClientName').val = ui.item.result;
            },
            width: 300,
            highlight: false,
            multiple: true,
            multipleSeparator: ","
       });
});
</script>

2 Answers 2

1

You are using .val() wrong:

$('#ClientName').val(ui.item.result);

See jQuery's documentation on .val()

Sign up to request clarification or add additional context in comments.

Comments

0

Remove $('#ClientName').val = ui.item.result; from select function and it will be like this

 select: function (event, ui) {
        }

Then use the following code that calls when you select value in customer:

$( "#customer" ).on( "autocompleteselect", function( event, ui ) {
      var customer = $("customer").val(); //getting customer name
      $("#ClientName").val(customer);     //setting the client name
});

2 Comments

Thanks for your reply. I tried the way you have recommended but still i am not getting the output. For testing purpose i placed an alert - that is also not popping up.
sorry! i forget '#' now try like this var customer = $("#customer").val(); on second line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.