Skip to content

Instantly share code, notes, and snippets.

@dd701116
Created February 20, 2024 15:37
Show Gist options
  • Save dd701116/2cf20c14a32e1c92e45e974750ef4b29 to your computer and use it in GitHub Desktop.
Save dd701116/2cf20c14a32e1c92e45e974750ef4b29 to your computer and use it in GitHub Desktop.
Search in select options
const searchInput = document.getElementById("search-in-select-input")
const selectTagToManage = document.getElementById("csvBoxAbove")
function searchInSelect(value) {
for (let index = 0; index < selectTagToManage.options.length; index++) {
selectTagToManage.options[index].hidden = !(new RegExp(`${value}`, "ig")).test(selectTagToManage.options[index].value)
}
}
searchInput.addEventListener("keyup", () => searchInSelect(searchInput.value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment