Resolve wrong message during the selection of items by checkbox
In a list page If i checked the header checkbox, system showing wrong message "4 ITEM(S) SELECTED" but there only 3 items present
On a listing page there 3 items are present, but when I select the select all checkbox system showing 4 items is selected. There is a variable "countCheckedCheckboxes" that define the length of the table values. At first, I think if I decremented the countCheckedCheckboxes value 1 then it's OK.
But there is a problem if the counted total length value is always countCheckedCheckboxes -1 then the first checkbox length always be counted as 0(zero).
That why i set a new class on
that count the lenght of content.
$(document).ready(function(){
var checkboxes = $('input[type="checkbox"]');
checkboxes.click(function(){
var countCheckedCheckboxes = checkboxes.filter(':checked').length;
if(countCheckedCheckboxes > 0){
$('.label_info').text(countCheckedCheckboxes-1+' item(s) selected');
}else{
$('.label_info').text('No item selected');
}
});
});
$(".checkSelect").change(function () {
var lenghtCheck= $('input[class="checkSelect"]:checked').filter(':checked').length //that check the length of table content's
//the variable lenghtCheck that count the length of table content.
if( lenghtCheck > 0){
$('.label_info').text(lenghtCheck+' item(s) selected');
}else{
$('.label_info').text('No item selected');
}
});
Conclusion:
You can use the code in NodeJS development. Please share your reviews in the comment section. See you on my next blog.
TOP CATEGORY
LATEST BLOGS
How to Choose the Best Product Review App for Your Shopify Store to Boost Conversions in 2026
Shopify
Content Formatting for AEO: How Structure Impacts AI Answer Selection
AEO
Search Intent Mapping: The Missing Link Between SEO, AEO, and GEO Success
SEO
Mastering Microservices with Node.js: Best Practices for Scalable and Resilient Architecture
Node js
A Comprehensive Guide to Local SEO For Small Businesses
SEO
Google Fit with Flutter: A Step-By-Step Guide
Flutter
Comments