Reputation: 15
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>
Upvotes: 0
Views: 287
Reputation:
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
});
Upvotes: 0
Reputation: 4110
You are using .val()
wrong:
$('#ClientName').val(ui.item.result);
See jQuery's documentation on .val()
Upvotes: 1