set some specific options in multiselect as disabled and selected

how to disable multi select dropdown
disable option in select jquery
jquery disable select option based on value
html select first option not selectable
bootstrap select disabled
html hide option in dropdown
how to disable select list
jquery disable dropdown option

I have a multiselect box having some options which i am able to select or disable via jquery, but i am not able to make them do both at the same time. How can i do that via jquery ??

Here's what i was doing - JSFiddle

In this example i am selecting an option on load and after that disabling it, but the option is still de selectable. I want to keep it selected and disabled all the time.

For now i am using click method to keep it selected by adding this line:

$('#multiSelect').click(function()
{$('#multiSelectoption[value="three"]').attr('selected',true);});

EDIT: People are posting the solution where we select the option again on click, which i already have posted in my question. What i wanted to know is that if there exist some better solution as this one does not look good.

js fiddle:

http://jsfiddle.net/Tf5ZZ/5/

jquery:

//disabling on load:
$('#multiSelect option[value="three"]').prop('disabled', true);

$("#multiSelect option").on('click',function() {
    $('#multiSelect option[value="three"]').prop('selected',true);
});

Disable the jquery multiselect, form inputs don't get included in the POST / GET data. The <option> tag confirms that the select element has values or items in it. Therefore, first we will find the options. The second method .remove() will remove all the options in the select element. 2) Remove a Specific Select Option. You can remove a specific option from the list, using jQuery .remove() method.

If the point is to prevent the value of the select box from being changed after it's set then you should disable the select box instead of just the option item.

$('#multiSelect option[value="three"]').prop('selected',true);
$('#multiSelect').prop('disabled',true);

See this fiddle for demonstration: http://jsfiddle.net/zKbVm/1/.

Also, the difference between prop() and attr() is that attr() gets/sets the element's attributes (which reflect the inital state of the element) and prop() gets/sets its properties (which represent the current state of the DOM node). See https://stackoverflow.com/questions/5874652/prop-vs-attr for more information.

HTML form readonly SELECT tag/input, I set three options in multiselect, option1, option2 and option3. when I chose the option1 and option2, can the option3 be disabled dynamically. what should i do to realize this. not disable the options, but prevents from selecting more options​. Successfully merging a pull request may close this issue. When a user selects an option, we will display the corresponding div for that option and disable the option in the select element. The user can again enable the option by clicking on the remove link.

<select multiple="multiple" size="3">
    <option value="1" selected>One</option>
    <option value="2" disabled>Two</option>
    <option value="3" disabled>Three</option>
</select>

HTML option disabled Attribute, I currently want the user to select a maximum of 6 items. add the disabledClass class defined in your multiselect options (default: 'disabled')  I'm a user-friendlier drop-in replacement for the standard <select> with multiple attribute activated. Activates your content as a multiselect. Accepts an optional options object. Note: You must init the multiple select with $ ('#your-select').multiSelect () before calling one of the following methods. Select the item with the value given in

I guess you could handle that in the create event of multiselect which is called after the widget gets created.

Below is the code snippet which I am using in the current application I am working on;

create: function (event, ui) {
    $(this).multiselect("widget").find(":checkbox").each(function () {
        var checkBoxValue = $(this).val();
        // Using linq.js to query the fields and determine whether
        // the field is required in my case.
        // Replace this if statement with your own logic here
        if (Enumerable.From(CHAMP.cache.fields).Count(function (x) {
            return x.Id.toString() == checkBoxValue && x.IsRequired == true;
        }) > 0) {
            $(this).attr("checked", "checked");
            $(this).attr("disabled", "disabled");
        }
    });
}

how to disable an option in multiselect dynamically · Issue #891 , The disabled attribute can be set to keep a user from selecting the option until some other condition has been met (like selecting a checkbox, etc.). Then, a  The disabled attribute can be set to keep a user from using the drop-down list until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript can remove the disabled value, and make the drop-down list usable.

Here is a small piece of jQuery to solve your problem.

 $("#multiSelect option").click(function()
 {
      $("#multiSelect option[value='three']").prop("selected", true);
 });

Can't disable the multi-select after initialisation · Issue #62 · lou/multi , <option value="mercedes">Mercedes</option> <option The disabled attribute can be set to keep a user from using the drop-down list until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript can remove  To enable multiple selection, you only need to set the dgMultiSelect element to "True" in the Options property. When dgMultiSelect is "True," users can select multiple rows in a grid using the following techniques: The selected rows/records are represented as bookmarks and stored in the grid's SelectedRows property.

HTML select disabled Attribute, If you set a certain option as disabled for the select html element to which the multiselect is attached, it won't be displayed at all as an option in  Options. A traditional <select> box contains any number of <option> elements. Each of these is rendered as an option in the dropdown menu. Select2 preserves this behavior when initialized on a <select> element that contains <option> elements, converting them into its internal JSON representation:

Option to disable multiselect items, An example on how to disable a selection of certain options in a MultiSelect and To prevent the drop-down list from closing, set the autoClose property. Edit Bootstrap Multiselect is a jQuery based plugin that allows users to tick multiple options from a standard Bootstrap select. Its implementation is quite simple, and in exchange brings a lot of UX value. Examples of Bootstrap Multiselect use: See the following mutliselect dropdown examples: MDB overwrites a standard select to replace it with our

Disable Items | Kendo UI MultiSelect for jQuery, Take advantage of special price drop on Super Bundles, UI Kits, Templates & Plugins. Topic: Multiselect element without disabled option has default selection, if I don't use a default disabled option in multiselect element, the first option will be At the moment you can just put a blank <option> with no text inside it as the  Add and Remove Options in Select using jQuery. GitHub Gist: instantly share code, notes, and snippets.

Comments
  • Just for reference purposes, jQuery's prop() method should be used for boolean properties like selected and disabled, and you can combine these together by passing through your properties as an object: $('#multiSelect option[value="three"]').prop({ disabled: true, selected: true });
  • Hi @ishan, please check my updated answer.
  • I have posted this click solution in my question itself. Please check my updated question.
  • your fiddle shows that it is not always selected but just disabled. if we click on other option selection is lost. so just for that i used this code. you have written any code for click. you have just done it on load
  • The point is to prevent only one of the option from getting changed while other options are still available.
  • Again, i already have this solution and was looking for more elegant one. Selecting the option again on clicking doesn't look nice. It has to look like a fixed option.