0

How I can make my drop down disable in Edit but enable in Create User. I have the drop down in MVC view and Create and Edit user in jquery. I already tried these but not making it disabled using any of these in jquery:

 $("#dropdown").prop("disabled", false);  

 $('#dropDownId').attr('disabled', true);

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

and in my MVC with when I have like this:

  <select id="organization" class="create-user-select-half" disabled>

it making it disabled but I can not again Enable it in jquery.

3
  • 1
    Your id is organization, not dropdown or dropDownId. $('#organization').attr('disabled', true); Commented Jan 5, 2017 at 22:25
  • $(#organization).prop('disabled', true) Commented Jan 5, 2017 at 22:25
  • learn.jquery.com/using-jquery-core/faq/… Commented Jan 5, 2017 at 22:28

4 Answers 4

7

You have to set

$("#dropdown").prop('disabled', true);

for disabling a control. To enable it again you have to call:

$("#dropdown").prop('disabled', false);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="organization" class="create-user-select-half" disabled>
  <option value="1">dsdsd</option>
  </select>

<button onclick="$('#organization').prop('disabled', false)">Enable</button>
<button onclick="$('#organization').prop('disabled',true)">Disable</button>

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

6 Comments

the remove is not working. so it is disabled in Create user as well.
Please check your jQuery selectors. Just added a fiddle.
it is working here, but maybe because I am enable and disable in the Modal it is different and I am missing something..
Please check the id of the dropdown and the selector in your jQuery script. id="organization" => $('#organization')
yes, it is correct, it make it disable but when I open the modal that is making is enable is not working.
|
1

you should remove the attribute all together in order to re-enable the dropdown.

$('#dropdown').removeAttr('disabled')

Comments

0

To enable all the child elements in a drop-down list:

for (var x = 0; x < $("#organization")[0].childElementCount; x++) { $('#organization')[0][x].disabled = false; }

Comments

0

a disabled item is un-clickable. you can use a div outside of your select tag.

<div class="editable">
      <select id="organization" class="create-user-select-half" disabled>
</div>

$(".editable").on("click", function () {
    $('#organization').prop('disabled', false)
});

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.