2

First I display a div container with disabled input fields.

$("#button").click(function() {
    $(".disable-input").prop('disabled', true);
})

And with a second button inside the displayed div container I want to enable the change for input fields after the first click and after the second one the enabled input fields should be disabled. For example: Display my customers via div container and inside this div container I can change them with a click on the button. What is my mistake?

var count = 0;
    if(count == 0) {
         $("#edit").click(function(){
            $(".disable-input").prop('disabled', false);})  
            count = 1;
    }
    if(count == 1) {
         $("edit").click(function(){
                $(".disable-input").prop('disabled', true);})
                count = 0;
    }
2

1 Answer 1

2

Use attr('disabled', 'disabled') and removeAttr('disabled') to do this

var count = 0;
    if(count == 0) {
         $("#edit").click(function(){
            $(".disable-input").attr('disabled', 'disabled');
            count = 1;
         });
    }
    if(count == 1) {
         $("edit").click(function(){
             $(".disable-input").removeAttr('disabled');
             count = 0;
         });
    }

The reason is that the presence of the 'disabled' attribute (regardless of value) on an input element is enough to cause the input to be disabled, whatever the value - i.e

<input type="text" disabled="false" />

...is disabled.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there the same procedure to show and hide textareas and div containers?

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.