This may not be the most efficient way, but it is the first thing that comes to my mind, and it works:
Assuming you have a filter button with id="apply"
...
$("#apply").click(function (e) {
e.preventDefault();
var number = $("[name='number']:checked").val();
var letter = $("[name='letter']:checked").val();
$("li").hide();
$("li[class='" + number + " " + letter + "']").show();
});
Better Version
As the above will fail if your li
elements have any other classes, here is an alternative approach using JQuery's filter
method:
$("#apply").click(function (e) {
e.preventDefault();
var number = $("[name='number']:checked").val();
var letter = $("[name='letter']:checked").val();
$("li").hide();
$("li").filter(function (index) {
return $(this).hasClass(number) && $(this).hasClass(letter);
}).show();
});
You can apply this logic to any event, such as change
for the radio buttons...
$("input[type='radio']").change(function () {
var number = $("[name='number']:checked").val();
var letter = $("[name='letter']:checked").val();
//check if both radios have selected values before proceeding
if (!number || !letter) return;
$("li").hide();
$("li").filter(function (index) {
return $(this).hasClass(number) && $(this).hasClass(letter);
}).show();
});
Of course, if any of your number
s are 0
then they will not pass the value check as it stands.