Reputation: 1505
I want to create multi autocomplete but i can just created single one. It has to work with different query. My code like this.
$(document).ready(function(){
$("#arama").keyup(function(){
data_getir($(this).val());
});
});
function data_getir(aranan)
{
$.ajax({
type: "POST",
url: "web.asmx/oku?aranan=" + aranan, //web service ve methodumuz
data: "{adres:'complete.ascx'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg){
$("#goster").html(msg.d)
}
});
}
function sec(kontrol){$("#arama").val($(kontrol).html()); $("#goster").html("");}
<div>
<input id="arama" type="text" style="width:150px; height:20px; font-size:11pt;" />
<div id="goster"></div>
</div>
And js: jquery-1.2.6.pack.js
How can i use it with another query in same page ?
Upvotes: 0
Views: 263
Reputation: 1573
just generate a new function and bind it to the other input you want to use as autocomplete field, there's no limit to how many autocomplete you can have in one page.
$(document).ready(function(){
$("#arama").keyup(function(){
data_getir($(this).val());
});
$("#autocomplete_bis").keyup(function(){
data_getautocomplete_bis($(this).val());
});
});
function data_getir(aranan)
{
}
function data_getautocomplete_bis(aranan){
$.ajax({
type: "POST",
url: "web.asmx/oku?new_query=" + aranan, //web service ve methodumuz
data: "{adres:'complete.ascx'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg){
$("#autocomplete_bis_goster").html(msg.d)
}
});
}
function sec(kontrol){
$("#arama").val($(kontrol).html());
$("#goster").html("");
}
<div>
<input id="arama" type="text" style="width:150px; height:20px; font-size:11pt;" />
<div id="goster"></div>
<input id="autocomplete_bis" type="text" style="width:150px; height:20px; font-size:11pt;" />
<div id="autocomplete_bis_goster"></div>
</div>
Upvotes: 1