Set as checked a checkbox recovered from Localstorage

Asked

Viewed 93 times

0

Guys I have a table that each product has the same add-ons and are chosen from a checkbox. Then I check with this function when refresh which were chosen and put checked but because they have extras with equal id then ta putting the product checkbox under also in checked.

function Adicionais() {
        var adicionais = JSON.parse(localStorage.getItem("Adicionais"));
        for (var x in adicionais) {
            $(".Adicionais .AdicionalEscolhido[value=" + adicionais[x].idAdicional + "]").parent().find(".quantidadeAdicional").val(adicionais[x].quantidade);
            // $(".Adicionais .AdicionalEscolhido[value=" + adicionais[x].idAdicional + "]").prop("checked", "true");
            if ($(".Adicionais .AdicionalEscolhido[value=" + adicionais[x].idAdicional + "]")) {
                $(".Adicionais .AdicionalEscolhido[value=" + adicionais[x].idAdicional + "]").hide();
                $(".Adicionais .AdicionalEscolhido[value=" + adicionais[x].idAdicional + "]").closest("div").find('button[class=close]').show();
            }
        }
    }
  • 1

    Your problem is very complicated to understand, try to explain a little more gives your doubt. Welcome to Stackoverflow, it’s interesting to read on tour to understand a little more about the site.

  • Marconi already managed to solve my problem I did one of the elements that I had with different id in the td of each product looking for a checkbox with id equal to the value of the checkbox stored in my localStorage there now I mark the checkbox that is actually linked to product of that TD and not putting all as checked like before with the function above I did so var checkbox = $(".Adicionais .produtoEscolhido[value=" + adicionais[x].idProduto + "]").parent().find("input.AdicionalEscolhido[value="+adicionais[x].idAdicional+"]").pro("checked","true");

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.