HTML list sorting filter

Any Recommendations on where to look to re order a list based on input, i have a list that has switches and what i am trying to do is some filtering to display checked switches

$("#check-sort-list").on('change', function() {
       var get_selected = $(this).val();
        
        alert(get_selected);
        
        if(get_selected == 1)
            {
                console.log(get_selected);
            }
        
        else if(get_selected == 2)
            {
                console.log(get_selected);
            }
        
        else if(get_selected == 3)
            {
                console.log(get_selected);
            } else 
                {console.log("No selection");}
    });

Open in new window



my list is just a normal html list with a label and a checkbox.
Alex LordAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Please show us the list and what you are wanting to use to sort it.

I am assuming <ul> ?

This is confusing. Name suggests checkbox - usage suggests dropdown
$("#check-sort-list").on('change', function() {
       var get_selected = $(this).val();

Open in new window


The rest of the code says nothing about what you want to do re sorting - what criteria do you use to sort
- Free form entry
- Checkbox / drop down selection

What in the list is used as the sorting field?
0
leakim971PluritechnicianCommented:
Test page : http://jsfiddle.net/es8ypn5u/

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        jQuery(function($) {
            var arrClass = { 1: "one", 2: "two", 3: "three"};
            var sortList = function() {
                $("#mylist li").hide();
                $(".check-sort-list:checked").each(function() {
                    var checkboxValue = $(this).val();
                    var classToDisplay = arrClass[ checkboxValue ];
                    $("#mylist li." + classToDisplay).show();
                });
            };
            $(".check-sort-list").on('change', sortList);
            sortList();
        });
    </script>
</head>
<body>
<input type="checkbox" class="check-sort-list" value="1" checked="checked">1<br>
<input type="checkbox" class="check-sort-list" value="2">2<br>
<input type="checkbox" class="check-sort-list" value="3">3<br>
<ul id="mylist">
    <li class="one">my number(s) : 1</li>
    <li class="one two">my number(s) : 1 2</li>
    <li class="one three">my number(s) : 1 3</li>
    <li class="two">my number(s) : 2</li>
    <li class="three">my number(s) : 3</li>
</ul>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.