Im very new to JavaScript so i don’t know if this is even possible. I have a searchbar with an autocomplete function and i also have a few buttons that can change my websites language:
//searchbar//
let availableKeywords = [
'example1',
'exapmle2',
'example3'
];
const resultsBox = document.querySelector(".result-box");
const inputBox = document.getElementById("query");
inputBox.onkeyup = function(){
let result = [];
let input = inputBox.value;
if(input.length){
result = availableKeywords.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 = '';
}
//buttons//
const langEl = document.querySelector(".langWrap");
link.forEach((el) => {
el.addEventListener("click", () => {
langEl.querySelector(".active").classList.remove("active");
el.classList.add("active");
});
I was wondering if it was possible that the content of availableKeywords could change language depending on wich language button is active?