JQuery to disable HTML buttons not working

I am trying to get jQuery to disable the confirmation button in my form if the dropdown is a specific value, but it doesn't seem to work.

I read a lot of posts here and tried different ways.

Here is my code at the moment:

    <script>
       $(document).ready(function () {
       // Handler for .ready() called.
       $('#MoveToCompanyId').attr("disabled", true);

       $('#DeleteAll').live("click", function () {

           if ($(this).attr("value") == "True") {
                 $('#MoveToCompanyId').attr("disabled", true);
           } else {
                 $('#MoveToCompanyId').attr("disabled", false);
                 $('#confirm').attr("disabled", true);
                 $('#MoveToCompanyId').change(function () {
                     if ($("#MoveToCompanyId option:selected").text() != "---Select Company---") {
                    $('#confirm').removeAttr("disabled");
                    alert($("#MoveToCompanyId option:selected").text());
                }
                else {
                    $('#confirm').attr("disabled", true);
                    alert("I should be disabled!");
                }

            });
        }
        });
     });

    </script>

Can anyone see any problems with it?

Just to clarify, I know that it falls into the correct blocks of code, since my warnings work. Its just a shutdown button that doesn't work.

Yours faithfully,

Gareth

+5
source share
3 answers

You have to use

prop('disabled',true)
prop('disabled',false)

if you are using jQuery 1.6+ then you should use prop.

Read more about prop

DOM HTML. , . .prop() .attr(). .val().

+10

.attr('disabled', 'disabled')

.removeAttr('disabled')

.

http://www.w3schools.com/tags/att_input_disabled.asp

+3

Try

 attr('disabled', 'disabled')  

instead

attr("disabled", true);
0
source

All Articles