Click here to Skip to main content
14,919,896 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello guys, I have a textbox, i want to autocomplete it , but seem it's not work.
JavaScript
window.onload = function () {
               load_text();
           }
           function load_text() {
               $.ajax(
               {
                   type: "POST",
                   url: "../BUS/WebService.asmx/LIST_DEPARTMENT",
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (data) {
                       //console.log(data);
                       var valuetextbox = [];
                       //$("#txt_textbox").html('');
                       $.each($.parseJSON(data.d), function (idx, obj) {
                           //$("#txt_textbox").append( obj.DEPARTMENT_NAME );
                           //alert(obj.DEPARTMENT_NAME);
                           valuetextbox.push(obj.DEPARTMENT_NAME);
                       });
                       //alert(valuetextbox);
                       $('#txt_textbox').autocomplete({
                           source: valuetextbox
                       });
                   },
                   error: function (data) {
                       alert("HTML Error Load");
                   }
               });
           }

This is data consolelog
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

Thank guys.
Posted
Comments
Kornfeld Eliyahu Peter 17-May-15 7:30am
   
"but seem it's not work" - you have to be more specific here!
Please describe any error message you may have...
headshot9x 17-May-15 7:41am
   
Dear Kornfeld Eliyahu Peter.
In here ,I want to when type a key as "H" , it's autocomplete "HR" , then i choose "HR" , textbox show text "HR" and it's hold value id follow name , in case "D00000000001" .Thank sir.
Kornfeld Eliyahu Peter 17-May-15 7:44am
   
I didn't ask you to explain what do to want to do, but to show what "but seem it's not work" means...
headshot9x 17-May-15 10:03am
   
Oh, I'm so sory. It's working @@. I try get value as follow row choose
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) {
$("#txt_textbox").val(obj.DEPARTMENT_ID);
}
});
},
error: function (data) {
alert("Error load");
}
});
}

It's error Uncaught ReferenceError: obj is not defined

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900