JavaScript disable bootstrap select option using javascript disable bootstrap select,disable bootstrap-select jquery,bootstrap disable select

I attempt to disable my specific bootstrap select option using javascript.

I know how to disable "normal select option", but when using bootstrap select it just didnt works (its disabled/greyed but i can still choose it) here jsfidle

<select name="dropdownBranch" id="dropdownBranch" class="selectpicker" data-live-search="true">
  <option value="0">Choose Number</option>
    <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>
<select id="pureDropDown">
  <option value="0">Choose Number</option>
    <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>
<button onclick="disableDropdown()">disable</button>



function disableDropdown(){
var selectobject;
selectobject=document.getElementById("dropdownBranch").getElementsByTagName("option");
    selectobject[3].disabled=true;

selectobject=document.getElementById("pureDropDown").getElementsByTagName("option");
    for(z=0;z<selectobject.length;z++){
        selectobject[z].disabled=true;
        }

}

i try to remove specific option too and the same case happen (work on normal dropdown but not work on bootstrap select)

Answer:1

As described here, you need to re-render the select picker after changing the disabled property of an option.

This should do the trick: (JSFiddle)

function disableDropdown(){
    var selectobject;
    selectobject = document.getElementById("dropdownBranch").getElementsByTagName("option");
    selectobject[3].disabled = true;
    $('#dropdownBranch').selectpicker('render');
}
Answer:2

use jQuery

$("#dropdownBranch").attr("disabled", "disabled");

or the pure javascript one:

function disableDropdown(){
    document.getElementById("dropdownBranch").setAttribute("disabled", "disabled");
}

JSFiddle

Answer:3

Try this

function disableDropdown(){
  var selectobject;
  selectobject=document.getElementById("dropdownBranch");
  selectobject.options[3].disabled=true;

  selectobject=document.getElementById("pureDropDown").getElementsByTagName("option");
for(z=0;z<selectobject.length;z++){
    selectobject[z].disabled=true;
}

}

Answer:4

Yo. Don't you just $.("selectedSelect").css("disabled", "disabled");

Okay. I apologize for my lack of effort. I realize my answer was flippant, and I chose to work on it more. Edit:

This is what I have come across on your jsfiddle. I am getting errors if I use .css, .val, .prop, or .attr. This is making me think that either jquery isn't working properly on jsfiddle for me, or I'm doing something wrong.

I dug deeper. I looked at the html. In jsfiddle, a bootstrap combobox is created above the select tag. I edited the combobox li with the value of 3 to have the class "disabled", and the desired result was obtained.

This led me to this code:

function disableDropdown(){
    var selectobject, optionList;
    selectobject=document.getElementById("dropdownBranch")
    .getElementsByTagName("option");
    selectobject = $("li");
    selectobject[3].addClass("disabled");


    selectobject=document.getElementById("pureDropDown")
    .getElementsByTagName("option");
    for(z=0;z<selectobject.length;z++){
        selectobject[z].disabled=true;
    }

}

What you need to do is access the bootstrap created element, and modify it to have the class disabled. Bootstrap should take care of the rest. I believe that you can do it in your own environment, but jsfiddle is annoying so I'm not going to continue working on this.

Answer:5

I want to format my HTTP headers using regex. I've done it using split(' ') followed by array manipulation, however this time I want to perform this operation using regex. I want to take this input ...

I want to format my HTTP headers using regex. I've done it using split(' ') followed by array manipulation, however this time I want to perform this operation using regex. I want to take this input ...

  1. sample http headers
  2. sample http header fields
  3. http headers formatting

I have : <script> var s="/xyz/abc/5-6-12-0-0-1-0"; document.write(s.match(/((\d+)$)/g)); </script> I've tried everything I know but I can not figure out how to get reasonable results "1"...

I have : <script> var s="/xyz/abc/5-6-12-0-0-1-0"; document.write(s.match(/((\d+)$)/g)); </script> I've tried everything I know but I can not figure out how to get reasonable results "1"...

  1. retrieve value javascript
  2. retrieve input value javascript
  3. retrieve form value javascript
  4. retrieve textarea value javascript
  5. retrieve select value javascript
  6. retrieve button value javascript
  7. retrieve css value javascript
  8. retrieve option value javascript
  9. retrieve value from javascript function
  10. retrieve value from javascript object
  11. retrieve label value javascript
  12. retrieve checkbox value javascript
  13. retrieve key value javascript
  14. retrieve value from javascript function in code behind
  15. retrieve number value javascript
  16. retrieve return value javascript
  17. retrieve value type javascript
  18. retrieve value from textbox javascript
  19. retrieve value from localstorage javascript
  20. retrieve value from dropdown javascript

I found myself wanting to return a 180 degree hue-rotated color from a function. My project's using D3, so that's the library I'm using to do this. Unfortunately, D3 doesn't come with a function to ...

I found myself wanting to return a 180 degree hue-rotated color from a function. My project's using D3, so that's the library I'm using to do this. Unfortunately, D3 doesn't come with a function to ...

I'm looking to append elements conditionally to a container based on whether the tags data matches the key variable. The way tags' data is returned is like tag1 tag2 tag3 tag4 tag5, the key is ...

I'm looking to append elements conditionally to a container based on whether the tags data matches the key variable. The way tags' data is returned is like tag1 tag2 tag3 tag4 tag5, the key is ...