Tuesday 12 January 2021

Get count and values of checked checkboxes using jquery:

<input type="checkbox" class="chkitem"/> Item1
<input type="checkbox" class="chkitem"/> Item2
<input type="checkbox" class="chkitem"/> Item3

1. To Get Count:
$('.chkitem:checkbox:checked').length;

2. To get values of checked checkboxes:
var selectedItems=[];
$('.chkitem:checkbox:checked').each(function () {
    selectedItems.push($(this).val());
});

No comments:

Post a Comment