Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 06, 2012 02:11 AM by asteranup
Member
84 Points
107 Posts
Nov 05, 2012 08:34 PM|LINK
Hi
I have form with Jqury UI autoComplate it is work fine. I am trying to input the customerID into input box value after user select name of Customer can someone help me
Html
<asp:TextBox ID="txtb_customersName" class="tb" runat="server"></asp:TextBox> <input type="text" id="CustomerID"/>
javascript
$(function () { $(".tb").autocomplete({ source: function (request, response) { $.ajax({ url: "WebServices/CustomerList.asmx/FetchCustomersList", data: "{ 'name': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { response($.map(data.d, function (item) { return { label: item.FirstName , value: item.FirstName , id: item.CustomerID } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false; }, change: function (event, ui) { try { if (event.originalEvent.type != "menuselected") { // Unset ID $("#CustomerID").val(""); } } catch (err) { $("#CustomerID").val(""); } } }); }, minLength: 2 });
Star
8376 Points
1573 Posts
Nov 05, 2012 09:14 PM|LINK
a_elnajjar82 select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false;
select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false;
Have you tried:
$("#CustomerID").val(ui.item.CustomerID);
All-Star
30184 Points
4906 Posts
Nov 06, 2012 02:11 AM|LINK
Hi,
a_elnajjar82 error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false;
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false;
You have made select as a part of ajax call. It should be part of autocomplete-
$(function () { $(".tb").autocomplete({ source: function (request, response) { $.ajax({ url: "WebServices/CustomerList.asmx/FetchCustomersList", data: "{ 'name': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { response($.map(data.d, function (item) { return { label: item.FirstName , value: item.FirstName , id: item.CustomerID } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false; }, change: function (event, ui) { try { if (event.originalEvent.type != "menuselected") { // Unset ID $("#CustomerID").val(""); } } catch (err) { $("#CustomerID").val(""); } }, minLength: 2 }) });
a_elnajjar82
Member
84 Points
107 Posts
append Selected Customer id to input box value?
Nov 05, 2012 08:34 PM|LINK
Hi
I have form with Jqury UI autoComplate it is work fine. I am trying to input the customerID into input box value after user select name of Customer can someone help me
Html
<asp:TextBox ID="txtb_customersName" class="tb" runat="server"></asp:TextBox> <input type="text" id="CustomerID"/>$(function () { $(".tb").autocomplete({ source: function (request, response) { $.ajax({ url: "WebServices/CustomerList.asmx/FetchCustomersList", data: "{ 'name': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { response($.map(data.d, function (item) { return { label: item.FirstName , value: item.FirstName , id: item.CustomerID } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false; }, change: function (event, ui) { try { if (event.originalEvent.type != "menuselected") { // Unset ID $("#CustomerID").val(""); } } catch (err) { $("#CustomerID").val(""); } } }); }, minLength: 2 });RichardY
Star
8376 Points
1573 Posts
Re: append Selected Customer id to input box value?
Nov 05, 2012 09:14 PM|LINK
Have you tried:
$("#CustomerID").val(ui.item.CustomerID);
asteranup
All-Star
30184 Points
4906 Posts
Re: append Selected Customer id to input box value?
Nov 06, 2012 02:11 AM|LINK
Hi,
You have made select as a part of ajax call. It should be part of autocomplete-
$(function () { $(".tb").autocomplete({ source: function (request, response) { $.ajax({ url: "WebServices/CustomerList.asmx/FetchCustomersList", data: "{ 'name': '" + request.term + "' }", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { response($.map(data.d, function (item) { return { label: item.FirstName , value: item.FirstName , id: item.CustomerID } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); }, select: function (event, ui) { $("#CustomerID").val(ui.item.id); return false; }, change: function (event, ui) { try { if (event.originalEvent.type != "menuselected") { // Unset ID $("#CustomerID").val(""); } } catch (err) { $("#CustomerID").val(""); } }, minLength: 2 }) });Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog