select option filter javascript

Solutions on MaxInterview for select option filter javascript by the best coders in the world

showing results for - "select option filter javascript"
Liah
28 Sep 2019
1    function filter() {
2        var keyword = document.getElementById("search").value;
3        var select = document.getElementById("select");
4        for (var i = 0; i < select.length; i++) {
5            var txt = select.options[i].text;
6            if (!txt.match(keyword)) {
7                $(select.options[i]).attr('disabled', 'disabled').hide();
8            } else {
9                $(select.options[i]).removeAttr('disabled').show();
10            }
11
12        }
13    }