vendredi 3 septembre 2021

How to keep checkbox checked when page refresh JavaScript, Spring Boot?

I am working on a ecommerce web app using Spring Boot. So there are multiple checkboxes for product filter according to various options like Price, Discount, Size etc. Below is my JavaScript function to update product listing page when category checkbox is checked.

function updatelisting(cid){
            debugger
            var checkboxid = 'checkbox'+cid;
            var c = [];
            $('[id="'+checkboxid+'"]').each(function(i,e){
                if($(e).is(':checked')){
                    c.push(e.value);
                }
            })  
            var category = c.join();
            var url = "api/searchbyfilter";
            $.post(url,{
                category : category,
            }, function(data, status) {
                if (data.status == "OK") {
                    if (data.statusCode == 1) {
                        var list = data.response;
                        if(list.length > 0){
                            for(var i = 0; i < list.length; i++){
                                window.location.href = "shopitems?type="+list[i].product.category.categoryid+"";
                                selecttab(<%=pagelength%>);
                            }
                        }else{
                            alert("No product found");
                        } 
                    } else {
                        var error = data.responseMessage;
                        swal(error, "", "error");
                    }
                } else {
                    var error = data.responseMessage;
                    swal(error, "", "error");
                }
            });
        } 

How to keep checkbox checked after page refresh or reload? How to write query parameter when passing multiple values in URL. Please suggest me some solution.




Aucun commentaire:

Enregistrer un commentaire