Reputation: 43
I need to redirect to another page when I click to Autocomplate Text Box . I try to put
select: function(event, ui) {
window.location.href = 'Search.aspx?q=' + ui.item.value;;
},
but it does not work when i click? What am ı need to solve this ?
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<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: "AutoCompleteService.asmx/GetAutoCompleteData",
data: "{'TurAdi':'" + document.getElementById('txtSearch').value + "'}",
idm: document.getElementById('txtSearch').value,
dataType: "json",
success: function (data) {
response(data.d);
},
select: function(event, ui) {
window.location.href = 'Search.aspx?q=' + ui.item.value;;
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<asp:TextBox ID="txtSearch" runat="server" CssClass="searchtxtb oval autosuggest" Width="172px" Height="25px" BackColor="White" Font-Bold="True" ForeColor="#666666" onfocus="if(this.value =='ARA:Tur, bölge veya belde adı' ) this.value=''"
onblur="if(this.value=='') this.value='ARA:Tur, bölge veya belde adı'" value="ARA:Tur, bölge veya belde adı"></asp:TextBox>
Upvotes: 1
Views: 2195
Reputation: 2546
The select: function (event, ui) { ... }
should be moved to be a sibling of source
, because it is an option of autocomplete
not of ajax
.
Like this -
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
// Put it here, as part of the autocomplete options.
select: function(event, ui) {
window.location.href = 'Search.aspx?q=' + ui.item.value;;
},
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoCompleteService.asmx/GetAutoCompleteData",
data: "{'TurAdi':'" + document.getElementById('txtSearch').value + "'}",
idm: document.getElementById('txtSearch').value,
dataType: "json",
success: function (data) {
response(data.d);
},
// Moved out of here, since it was an ajax
// option and it is unrelated to ajax.
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<asp:TextBox ID="txtSearch" runat="server" CssClass="searchtxtb oval autosuggest" Width="172px" Height="25px" BackColor="White" Font-Bold="True" ForeColor="#666666" onfocus="if(this.value =='ARA:Tur, bölge veya belde adı' ) this.value=''"
onblur="if(this.value=='') this.value='ARA:Tur, bölge veya belde adı'" value="ARA:Tur, bölge veya belde adı"></asp:TextBox>
Upvotes: 1