dimanche 5 avril 2015

Taking into consideration special characters in a search

I have a form with a search suggestion that appears as the user types in the input. Now this search suggestion is clickable, where users are able to click on a particular item. when that item it clicks it take them to something like searchPage.php?user_query=the text of the item that was click (i.e. searchPage.php?user_query=html).


What I notice is that if the search suggestion item has a special character known as ASCII ISO 8859-1 Characters it will disregard it, and hence the result would be searchPage.php?user_query=


Under no circumstances can it be blank because its bad design if you click on a item and then it populates you the entire list.


Below is the search suggestion js:



$(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();
window.open('searchPage.php?user_query=' + decoded,'_self',false);

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

}
});
$('#searchid').click(function(){
jQuery("#result").fadeIn();
});
});


Below is the form:



<form method="get" action="searchPage.php" enctype="multipart/form-data" autocomplete="off">
<input type="text" class="search" id="searchid" name="user_query" id="searchBar" placeholder="Search for courses" />
<input type="submit" id="searchButton" name="search" value="search" class="btn btn-danger" autocomplete="off"/>

<div id="result"></div>

</form>

Aucun commentaire:

Enregistrer un commentaire