Skip to content

Instantly share code, notes, and snippets.

@afsinka
Created August 2, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afsinka/0ae14a35f77962c84c104013556eeb06 to your computer and use it in GitHub Desktop.
Save afsinka/0ae14a35f77962c84c104013556eeb06 to your computer and use it in GitHub Desktop.
Filter in Select Option List With Textbox (Old Browser)
<script type="text/javascript">
$(document).ready(function() {
$("#searchBoxForOldBrowsers").keyup(function() {
searchInListForOldBrowsers();
});
});
var searchInListForOldBrowsers = function() {
var myOptions = document.getElementById($('#myOptions').get(0).id);
var searchBox = document.getElementById($('#searchBoxForOldBrowsers').get(0).id);
$.each(myOptions, function(index, item) {
$(item).css("visibility", "hidden");
$(item).attr("disabled", "true");
var writtenValue = item.innerText.toUpperCase();
var searchedValue = searchBox.value.toUpperCase();
if (writtenValue == "" || searchedValue == "" || writtenValue.indexOf(searchedValue) >= 0) {
$(item).css("visibility", "visible");
$(item).removeAttr("disabled");
if (searchedValue != "" && index != 0) {
$('select[name="' + document.getElementById($('#myOptions').get(0).id).name + '"] option:eq(' + index + ')').insertBefore(
$('select[name="' + document.getElementById($('#myOptions').get(0).id).name + '"] option:eq(0)'))
}
}
});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment