hi
i am using auto complete JS for to textboxs.for the first textbox its working properly but when i used to do the same code for the another texbox its not working. please check my code is below
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/GetAutoCompleteData",
data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest1").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/GetAutoCompleteData1",
data: "{'username1':'" + document.getElementById('txtSearch2').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<div class="span12">
<input id="txtSearch2" class="autosuggest1 span5" style="height: 30px;" type="text" placeholder="Photography Style,Occasion,Category">
<input style="height: 30px;" type="text" id="txtSearch" class="autosuggest span5" placeholder="Location: City">
<button type="submit" style="margin-top: -11px;" class="btn btn-warning btn-large">
Search </button>
</div>
C# code is
[WebMethod]
public static List<string> GetAutoCompleteData(string username)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=192.168.10.120;Initial Catalog=XXXX;User ID=XXX;password=XXX"))
{
using (SqlCommand cmd = new SqlCommand("select top 10 city from tbl_City where city LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", username);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["city"].ToString());
}
return result;
}
}
}
[WebMethod]
public static List<string> GetAutoCompleteData1(string username1)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=192.168.10.120;Initial Catalog=XXXX;User ID=XXX;password=XXX"))
{
using (SqlCommand cmd = new SqlCommand("select top 10 Category from Category where city LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", username1);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["city"].ToString());
}
return result;
}
}
}