Filtering html select listbox items
The efficient way of filtering select list box items may be achieved using JQuery
$(function(){
$('#filterInput').keyup(function () {
doFilter(this);
});
});
/* filter method */
function doFilter(item) {
$(item).val($(item).val().toUpperCase());
var valFilter = $(item).val();
var valFilter2 = null;
if ($(item).val().length > 2)
valFilter2 = $(item).val();
$('#listItems>option').each(function () {
var text = $(this).text();
(text.indexOf(valFilter) == 0 || (valFilter2 != null && text.includes(valFilter2) == true)) ? $(this).show() : $(this).hide();
});
}
$(function(){
$('#filterInput').keyup(function () {
doFilter(this);
});
});
/* filter method */
function doFilter(item) {
$(item).val($(item).val().toUpperCase());
var valFilter = $(item).val();
var valFilter2 = null;
if ($(item).val().length > 2)
valFilter2 = $(item).val();
$('#listItems>option').each(function () {
var text = $(this).text();
(text.indexOf(valFilter) == 0 || (valFilter2 != null && text.includes(valFilter2) == true)) ? $(this).show() : $(this).hide();
});
}
Comments
Post a Comment