0

In my fiddle here:http://jsfiddle.net/qJdaA/2/ this code is suppose to disable the #monitor button when there is none checked checkbox.

        var checked = $('#status_table tr [id^="monitor_"]:checked');
        if (checked.index()==-1){
            $('#monitor').attr('disabled','true');

        }

But it does not seem to be working. What's wrong?

EDIT: i found out i'm getting blurred with my code. to simplify the whole thing, may be i should change the logic :s How should i do it if i want to enable the monitor button ONLY if there is at least a checkbox been checked?

yvonnezoe
  • 7,129
  • 8
  • 30
  • 47

2 Answers2

3

Try using this condition:

if (checked.length === 0) {

And you should use .prop(), not .attr() for setting the disabled state (as well as things like checked and selected).

So it would be:

$("#monitor").prop("disabled", true); // (or false, to enable it)

References:

Community
  • 1
  • 1
Ian
  • 50,146
  • 13
  • 101
  • 111
  • Thank you for the answer. i realized that there is much other problems with the code now (please refer my edited question). Thank you again :) – yvonnezoe May 15 '13 at 03:30
1

Try

$('#monitor').prop('disabled',true);

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • but it seems the same :( i think there may be other problems. please see my edited question above. thank you! :) – yvonnezoe May 15 '13 at 03:31