etoolclub etoolclub - 2 days ago 3
HTML Question

Jquery get total checkbox in current page and calculate no. of them are checked in page load

I am trying to get total number of checkbox in my current page and how many of them are checked using following scripts:

$(window).load(function() {
var chk_total=$('input[type='checkbox'].order_row:checked').length;
var in_total=$('input[type='checkbox'].order_row').length;
if (chk_total == in_total) {
alert("all cheked");
}

}


Html scripts:

<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>
<input type="checkbox" class="order_row"/>


But above scripts doesn't working for me. Could please tell me why it's not working ?

Answer

Your js scripts has errors please update that as follow then try again.

var chk_total=$('input[type="checkbox"].order_row:checked').length;
var in_total=$('input[type="checkbox"].order_row').length;
if (chk_total == in_total) {
   alert("all cheked");
}

Or use following scripts:

   var chk_total=$('.order_row:checked').length;
    var in_total=$('.order_row').length;
    if (chk_total == in_total) {
       alert("all cheked");
    }  
Comments