25

I want to disable control on click for this i have added attr to the control 'disabled' and it is working fine in IE but not in Firefox. The code i have written is

$(obj).attr('disabled','disabled');

If I am missing something then please give me idea.

Alex R.
  • 4,394
  • 4
  • 28
  • 40
munish
  • 251
  • 1
  • 3
  • 3

5 Answers5

42
$(obj).attr('disabled', true);
Alex R.
  • 4,394
  • 4
  • 28
  • 40
8

Try this

$(obj).attr("disabled","disable")

note value of attribute "disabled" is "disable" not "disabl*ed*"

Chinmayee G
  • 7,437
  • 1
  • 29
  • 41
  • 3
    Your solution is solving problem but it's not real answer. Value of disabled attribute isn't important. you can only write attribute without value and control will be disabled again. You can try to write $(obj).attr("disabled","enable") and control will be disabled again. – MERT DOĞAN Oct 31 '14 at 08:10
6

This is the code I use to disable or re-enable a control:

function handleControlDisplay(className, foundCount, checked) {



    var button = jQuery(className);



    if (foundCount > 0 && foundCount == checked) {

        // enable

        button.removeAttr("disabled");

    }

    else {

        // set the disabled attribute

        button.attr("disabled", "true");

    };

}
CarneyCode
  • 3,451
  • 3
  • 24
  • 45
2

The very complete answer is here: Disable/enable an input with jQuery?

TL;DR use the .prop() method

$("input").prop('disabled', true);
$("input").prop('disabled', false);
grahamesd
  • 4,103
  • 1
  • 24
  • 26
0

Here's an example of disabling a button after it has been clicked. Notice that you pass the "this" object to the click event handler :

<input type="button" value="Submit" onclick="disable(this)"/>

And the javascript:

    <script>
     function disable(control){
       control.disabled = true;
      }
   </script>
Fabian Madurai
  • 153
  • 1
  • 4