How to custom data text value in autocomplete ?
Hello guys.
I have try show data and get value using autocomplete jquery. Textbox will show data choose and label will get value .But it's error
-
Uncaught TypeError: Cannot read property 'DEPARTMENT_ID' of undefined
.
This is data JSON when i see console.log
- Object {d: "[{"DEPARTMENT_ID":"D00000000001","DEPARTMENT_NAME"…"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false}]"}
- d: "[{"DEPARTMENT_ID":"D00000000001","DEPARTMENT_NAME":"HR","DEPARTMENT_DES":"HR","EDIT_DATE":"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false},
- {"DEPARTMENT_ID":"D00000000002","DEPARTMENT_NAME":"ACCOUNT","DEPARTMENT_DES":"ACCOUNT","EDIT_DATE":"2015-05-05T00:00:00","EDIT_BY":"","FLAG":false}]"
- __proto__: Object
and this is function
- function load_text() {
$.ajax(
{
type: "POST",
url: "../BUS/WebService.asmx/LIST_DEPARTMENT",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var valuetextbox = [];
$.each($.parseJSON(data.d), function (idx, obj) {
valuetextbox.push(obj.DEPARTMENT_NAME);
});
$('#txt_textbox').autocomplete({
source: valuetextbox,
select: function (event, ui) {
$("#label_value").val(ui.item.obj.DEPARTMENT_ID);
}
});
},
error: function (data) {
alert("Error load");
}
});
}