Jquery Autocomplete Selected value split in two text boxes -


i looking functionality split selected items jquery autocomplete dropdown in 2 different text boxes.

so far tried following isn't working:

$(".autocomplete").autocomplete({   source: function (request, response) {     var param = { lockeyword: $('[id*=txtcity]').val() };     $.ajax({       url: "/upslocator.aspx/getquerydata",       data: json.stringify(param),       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 {             value: item           }         }))       },       error: function (xmlhttprequest, textstatus, errorthrown) {         var err = eval("(" + xmlhttprequest.responsetext + ")");         alert(err.message)         // console.log("ajax error!");         }     });   },   select: function (event, ui) {     var selectedval = ui.item.value;      alert(selectedval);     debugger;     var array = selectedval.split(',')     $('[id*=txtcity]').val(array[0]);     $('[id*=txtstate]').val(array[1]);   },   minlength: 6 //this char length of inputtextbox   }); 

i getting following response above snippet.

{city, state} 

i able set value state city textbox set city,state it's not splitting.

do have access manipulate data?

the autocomplete widget expects array of json objects label , value properties (although if specify value, used label). in simplest case, can return data looks this:

[     { state: 'texas', city: 'san antonio' },      { state: 'texas', city: 'dallas' },     { state: 'texas', city: 'austin' } ]  select: function( event, ui ) {    $("#txtstate").val(ui.item.state);           $("#txtcity").val(ui.item.city); } 

there example data:

https://jsfiddle.net/dabc61ma/1/


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -