Show number of checked checkboxes taking into account records already existing in the database

0

Hello, I have a script that does an update to the database every time I mark the checkbox without the client seeing;

        <script> 
        $(document).ready(function() { 
            $('.check').click( function () { 
                if ($(this).is(':checked')) { 
                    $.post("altera.php", { checado : '0', id: $(this).val() }, function () { 
                    }); 
                } else { 
                    $.post("altera.php", { checado : '1', id: $(this).val() }, function () { 

                    }); 
                } 
            }); 
        }); 
    </script>

and another that counts the checkbox number that the customer has already selected;

        var contador = function() {
        var n = $("input:checked").length;
        $(".checkcount").text((n === 0 ? "" : "Já foram selecionadas ") + n + (n === 1 ? " foto" : " fotos") + "" );
        };
        contador(); 
        $( "input[type=checkbox]" ).on( "click",contador);

The problem is that I could not make this second code take into account the first one because when I select the checkboxes on the same page it's a normal account but when I change the page it shows zero because it does not consider the checkboxes that have already been marked in the bank of data by the first code;

    
asked by anonymous 06.08.2015 / 22:24

0 answers