0

i need to filter data attribute using jQuery. First i want to filter via selectbox and then filter with checkbox. All i want is when i checked both textbox, data will display all. But now, it only show the first data checkbox. Please see fiddle. https://jsfiddle.net/legazy7891/t9krfjpy/4/

At if condition i've tried :

if ($('.3').is(':checked')) { chkBox.datatest = "1"; } 
 else if ($('.4').is(':checked')) { chkBox.datatest = "6"; } 
 else if ($('.3').is(':checked') && $('.4').is(':checked')) { chkBox.datatest = ""; } 
 else { chkBox.datatest = ""; }

But it doesn't work.

Reference : JQuery - Filtering data attributes with multiple filters of different inputs

Any help would be appreciate. Thanks

1 Answer 1

1

The issue is with the order of the condition. When you select both check box, the first condition will get satisfy $('.3').is(':checked') and chBox.dataset will get set to 1. It won't go to third condition.

Try following

if ($('.3').is(':checked') && $('.4').is(':checked')) {
   chkBox.datatest = "";
} else if ($('.3').is(':checked')) {
   chkBox.datatest = "1";
} else if ($('.4').is(':checked')) {
   chkBox.datatest = "6";
} else {
   chkBox.datatest = "";
}
Sign up to request clarification or add additional context in comments.

1 Comment

How about if i have more than 2 checkboxes? i think i need better method instead of add condition in every single checkbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.