Created
August 2, 2017 18:46
-
-
Save afsinka/0ae14a35f77962c84c104013556eeb06 to your computer and use it in GitHub Desktop.
Filter in Select Option List With Textbox (Old Browser)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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