1

I have a column in the table consists of checkboxes, I need to check whether all the checkboxes are disabled.

Here is my code

var checkBoxTdSize = $('.hrchy-dt-checkboxes').length;
    var checkedFlag=false;
    for(var t=0;t<checkBoxTdSize;t++){
        var chk = $(this).find('.hrchy-dt-checkboxes')[t];
        if ($(chk).prop('disabled')==true){ 
            checkedFlag=true;
        }else{
            alert('Please Map all the Hierarchy..!');
        }
    }
    if(checkedFlag){
       //Some Code
    }

But from the above code I always get alert "Please Map all the Hierarchy..!".

Help is appreciated, Thanks

eThan_hunT
  • 244
  • 5
  • 23

4 Answers4

3

Should be as simple as comparing the length of all the checkboxes to the length of all the disabled checkboxes, if it's the same, they are all disabled

if ( $('.hrchy-dt-checkboxes').length === $('.hrchy-dt-checkboxes:disabled').length  ) {...
adeneo
  • 312,895
  • 29
  • 395
  • 388
2

You need to check if the disabled attribute is true.

example below:

function test() {
  $(".hrchy-dt-checkboxes").each(function() {
     if ($(this).is(":disabled")) {
        // your action here test using is function
     }

     if ($(this).attr("disabled")) {
       // your action here test using attribute function
     }
  });
} 

$(document).ready(function() {
   test();
});
Fernan Vecina
  • 144
  • 1
  • 8
2

If your checkboxes are not in any parent then why you are using find() method...?

$(document).ready(function() {
    var chk = $('.hrchy-dt-checkboxes');
    chk.each(function(index, el) {
        if ($(this).prop('disabled') == true) {
            //your code here
        }
    });
});

$(document).ready(function() {
    var chk = $('.hrchy-dt-checkboxes');
    chk.each(function(index, el) {
        if ($(this).prop('disabled') == true) {
         var condi = true;
         console.log('Disabled = ' + condi)
        }
        else {
         console.log('Enabled..!')
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes" disabled="disabled">
Rohit Sharma
  • 3,304
  • 2
  • 19
  • 34
1

You can use something like this

var x = document.getElementById("myCheck").disabled;

Than x would be true or false.

Source

Dragomir Kolev
  • 1,088
  • 10
  • 25