mardi 31 mars 2015

Working with search suggestion

I have the following search suggestion script, where as a user types dynamically the result is updated. What I would want is that when a user click on one of the suggestion it takes them to the `following:searchPage.php?user_query=what the user has typed in the input


Below is the script



$(function(){
$(".search").keyup(function()
{
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;
});

jQuery("#result").live("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.name').html();
var decoded = $("<div/>").html($name).text();
$('#searchid').val(decoded);
});
jQuery(document).live("click", function(e) {
var $clicked = $(e.target);
if (! $clicked.hasClass("search")){

window.open('searchPage.php?user_query=','_self',false);
}
});
$('#searchid').click(function(){
jQuery("#result").fadeIn();
});
});


At its current state it just open the window to searchPage.php but doesn;t take into account in the url what the user has entered; the desired result is searchPage.php?user_query=what ever you want


Aucun commentaire:

Enregistrer un commentaire