|
 |
|
jQuery AutoComplete ใครรู้วิธีบ้างครับ ตอนเลือกข้อมูล |
|
 |
|
|
 |
 |
|

Code (JavaScript)
$("#ctl00_ContentPlaceHolder1_TxtDocNO").autocomplete(
{
source: function (request, response) {
$.ajax({
url: "PageAEUser.aspx/Get_Doc_ById",
data: "{'keyword':'" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
val:item.split('#')[0],
label:item.split('#')[1],
doc_no:item.split('#')[2],
doc_name:item.split('#')[3]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("#ctl00_ContentPlaceHolder1_Hdn_doc_id").val(i.item.val);
$("#ctl00_ContentPlaceHolder1_TxtDocNO").val(i.item.doc_no);
$("#ctl00_ContentPlaceHolder1_TxtName").val(i.item.doc_name);
},
minLength: 4
});
คือเวลาเรากดเลือก ค่าที่เราค้นหา ค่านั้นมันจะถูกนำมาใส่ TextBox ให้
ซึ่งผมไม่ต้องการค่าที่กดเลือก แต่ผมจะเอาค่า อื่นมาใส่ ตอน Select แทน
โดยกำหนดค่าต่างๆ ไว้ดังนี้
Code (JavaScript)
select: function (e, i) {
$("#ctl00_ContentPlaceHolder1_Hdn_doc_id").val(i.item.val);
$("#ctl00_ContentPlaceHolder1_TxtDocNO").val(i.item.doc_no);
$("#ctl00_ContentPlaceHolder1_TxtName").val(i.item.doc_name);
},
ซึ่ง ค่าใน TextBox มันไม่เปลี่ยนตามที่ผมกำหนดครับ เนื่องจากมันจะเอาค่าที่เราเลือกมาใส่แทน
ใครมีวิธีกำหนดค่าให้ TextBox บ้างครับ
Tag : ASP

|
|
 |
 |
 |
 |
Date :
2014-02-24 23:47:50 |
By :
เซ็ง Login แล้วโพสไม่ขึ้น |
View :
801 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมเคยใช้การ Apply ด้วยการใช้การตัด string เอาครับ 
|
 |
 |
 |
 |
Date :
2014-02-25 21:11:50 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|