I have copied an youtube tutorial of how to make an “autocomplete search bar” – Made By GreekStack, Everything is working fine I was just windering if there was an way to actually redirect the user to an different HTML page.
I would like to make my search bar be able to redirect users to an different HTML page. This is made with Javascipt, HTML, and CSS.
Here Is My Javascript:
let avaliableKeywords = [
'6TEST6',
'5TEST5',
'4TEST4',
'3TEST3',
'2TEST2',
'1TEST1',
];
const resultsBox = document.querySelector(".result-box")
const inputBox = document.getElementById("input-box")
inputBox.onkeyup = function(){
let result = [];
let input = inputBox.value;
if(input.length){
result = avaliableKeywords.filter((keyword)=>{
return keyword.toLowerCase().includes(input.toLowerCase());
});
console.log(result);
}
display(result);
if(!result.length){
resultsBox.innerHTML = '';
}
}
function display(result){
const content = result.map((list)=>{
return "<li onclick=selectInput(this)>" + list + "</li>";
});
resultsBox.innerHTML = "<ul>" + content.join('') + "</ul>";
}
function selectInput(list){
inputBox.value = list.innerHTML
resultsBox.innerHTML = '';
}