jeudi 30 avril 2015

Unable to count checked checkboxes from another page with jquery

I have multiple set of checkboxes. I want to count a particular set of checkboxes.These checkboxes given the class 'sub'. The interesting part is, they are fetched by an akax call from another php page. So the counter isn't working.

<script>
$("[id^=sub][type=checkbox]").change(function () {
    $('#count').text($("[id^=sub][type=checkbox]").length);
});
</script>

When I use below script, the checkboxes which is in the html page itself, it counts the very first set of the checkboxes! These are the checkboxes clicked to fetch those sub checkboxes!

Now how do I count that particular checkboxes of 'sub' class which are fetched by ajax call please?

<script>
$("input:checkbox").change(function () {
    $('#count').text($("input:checkbox:checked").length);
});

</script>

This is the fetched checkboxes structure.

<input type="checkbox" class="sub" name="sub['.$subjects_id.']" id="sub" value="">

ANd I display the count in the html page like this:

<p id="count"></p>




Aucun commentaire:

Enregistrer un commentaire