0

I have a form with a random number of checkboxes. I' trying to toggle them on/off via jquery when the top one is checked/un-checked BUT skip any checkboxes that are disabled. The first checkbox has an id of "select_all" and the jquery is shown below. This works fine the FIRST time, but all subsequent attempts fail. I don't see any errors in Chrome's console. Any ideas? I don't care if I use this code or something else.

<script>
    $('#select_all').click(function() {
        var c = this.checked;
        if(c == true){
            $('input:checkbox:not(:disabled)').attr('checked','checked');
        } else {
            $('input:checkbox:not(:disabled)').removeAttr('checked');
        }
    });
</script>
JoeByrne
  • 13
  • 4

1 Answers1

0

Try replacing

var c = this.checked;

For this

var c = $(this).prop('checked');

And your if condition to something like:

If(typeof c !== 'undefined')
Luis Deras
  • 1,239
  • 2
  • 19
  • 48