I used ajax to create a live search connected to the database(site e-commerce). when there is a value in the input several suggestions are fetched in the screen . I want to take the id when the client click in a suggestion. The suggestions cant be clickable i dont know why!! here is my jquery code :
$('.clicked').click(function() {
console.log($("#input_value").val());
});
var x;
var value = $("#input_value").val();
$('.clicked').click(function() {
$.ajax({
type:'GET',
// // url: 'test.php?name=' + $("#testo").val(),
data: { name : value },
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
success: function()
{
window.location.href = 'un_produit.php?id=' + $("#input_value").val();
}
});
I tried to add the class to a div and it works when i click but it doesnt work with the suggestions of the live search .
2
Answers
The problem is solved, I had to add the
class="clicked"
into the the child element of the suggestion div and not to the div itself. thank youInstead of using an
AJAX
request you could useJQUERY
autocomplete.This is an easy example on how this works, your URL source should return the data in this format:
I used this url as reference: https://www.codexworld.com/autocomplete-textbox-using-jquery-php-mysql/