SO - 30190290
by Arun P Johny
HTML
<div id="demo"> </div>
<div class="item">
<form id="aForm" onchange="filter()">
<input type="checkbox" id ="A" value="A"/>Exclude words with 'A'<br/>
<input type="checkbox" id ="E" value="E"/>Exclude words with 'E'<br/>
<input type="checkbox" id ="O" value="O"/>Exclude words with 'O'<br/>
</form>
</div>
JavaScript
var animals = ["Bear", "Mouse", "Cat", "Tiger", "Lion"];
function filter() {
var a = document.getElementById('A').checked,
e = document.getElementById('E').checked,
o = document.getElementById('O').checked,
result2; //make a copy
result2 = animals.filter(function (value) {
value = value.toLowerCase();
return (!a || value.indexOf('a') == -1) && (!e || value.indexOf('e') == -1) && (!o || value.indexOf('o') == -1);
})
document.getElementById("demo").innerHTML = result2;
}
filter();