I am currently working with Prestashop 1.7 and have encountered an issue with the Search by Brand functionality in the ps_facetedSearch module. While it works perfectly under the dropdown list form, I need to override this search and use an input field instead.
My solution is to check if the text entered in the input field exists in the dropdown list. However, despite console logging the variables txtValue and inpted to show their contents, the console displays no output. This is where I require assistance with the JavaScript script itself to ensure that it properly tests if the inputted text exists in the dropdown list.
Here is the HTML code for the faceted search module:
<div class="dropdown-menu" id="dropdown-menu">
<a rel="nofollow" href="http://archivartshop.local/fr/2-accueil?q=Marque-Naim+Ameur" class="select-list"> Naim Am(1)</a>
<a rel="nofollow" href="http://archivartshop.local/fr/2-accueil?q=Marque-Sonia+Mili" class="select-list"> Sonia Mili (1) </a>
<a rel="nofollow" href="http://archivartshop.local/fr/2-accueil?q=Marque-Yosr+Ben+Hammouda" class="select-list"> Yosr Ben Houda(2)</a>
</div>
Below is my JavaScript script for this task:
function mFn(){
divLi = document.getElementById("dropdown-menu");
linka = divLi.getElementsByTagName("a");
for (i = 0; i < linka.length; i++) {
var txtValue = linka[i].textContent ;
// console.log(txtValue); content displayed
var inpted = $('#search_input').val();
// console.log(inpted);content displayed
if( txtValue === inpted)
{
console.log("it_works");
}
else {
console.log("No !!");
}
}
}
Your help with resolving this issue would be greatly appreciated.