Reputation: 417
I made auto complete to a textbox as shown below,
<input type='text' style='width:100px;' id='tags'>
Here is the function which is loading auto complete on page load.
window.onload=function Search_Items() {
var action = "Search";
$.ajax({
method:'GET',
url:'Ajax.php',
data: {action:action},
success:function(result) {
document.getElementById("Search_Result_Div").innerHTML=result;
var temp=document.getElementById("Search_Result").value;
availableProducts=temp.split("`");
$(function() {
var Product=$( "#tags" ).autocomplete({
source: availableProducts,
select: function () {Data_Modification($(this).val());}
});
Product.autocomplete('option','onclick').call(Product);
});
}
});
};
Here i just called a function and passed a value (value is what chosen in auto-complete). But here it's not passing value what i choose instead it's passing what i typed for searching.
What i inferred is, it's calling function and then populate the textbox with value what is chosen. But i need to populate the textbox with chosen value and then call that function. How do i resolve it? Please if someone got this problem before. Help me out please.
Upvotes: 0
Views: 326
Reputation: 223
Try this
$(function() {
var Product=$( "#tags" ).autocomplete({
source: availableProducts,
select: function (event, ui) {Data_Modification(ui.item.value);}
});
Product.autocomplete('option','onclick').call(Product);
});
Upvotes: 2
Reputation: 417
I found a solution myself. I rewrote this
select: function () {Data_Modification($(this).val());}
to
select: function (event,ui) {Data_Modification(ui.item.value);}
and it's works fine.
Upvotes: 0