I want to make the option element tags inside a div clickable. More like a select tag. You might think, why I cannot use a select element. In my case, I need a search bar with a menu. Therefore I have used an input. I tried it in the following way. Seems like the value attribute isn't assignable and it is not clickable. Does anyone have any idea about this?
html:
<input id="searchInput" list="searchList" type="text" placeholder="Search.." onkeyup="filterFunction()">
<div id="searchList" class="dropdown-content">
</div>
javascript:
function fillList(elementIdentifier, data) {
const list = document.querySelector(elementIdentifier);
data.errorMessages.forEach(element => {
const option = document.createElement('option');
option.value = element.MessageId;
option.label = element.namespace + ": " + element.message;
list.appendChild(option);
});
}
function filterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("searchInput");
filter = input.value.toUpperCase();
div = document.getElementById("searchList");
a = div.getElementsByTagName("option");
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}