26

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.

2

5 Answers 5

42
$(obj).attr('disabled', true);
Sign up to request clarification or add additional context in comments.

Comments

8

Try this

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

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

1 Comment

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.
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");

    };

}

Comments

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);

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.