Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "disable" attribute for class "selectpicker" using jQuery

How to remove select"disabled" attribute at 2nd Dropdown using jquery when 1st Dropdown is selected.

I have tried some solutions but not solve my problem. The solution that I have tried as below:

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

2) $("#xyz").attr('disabled', true).trigger("liszt:updated");

Share my codes as below:

HTML

//This is 2nd Dropdown    
<select id="xyz" class="selectpicker form-control" multiple title="-- Select --" disabled>
       <option value="" disabled>-- Select --</option>
       <option value="A">A</option>                                     
       <option value="B">B</option>                                     
    </select>

JS

$("#1stdropdown").change(function() {       //This is 1st Dropdown      
    if ($("#1stdropdown").val() == "") {
        $("#btnSubmit").attr('disabled', true);
        $("#xyz").append($("<option>",{value: "",text: "-- Select --"}));
    }
    else {
        $("#btnSubmit").attr('disabled', false); 
        $("#xyz").removeAttr("disabled").prop("disabled", false);  // I am stuck here
    }
});
like image 666
mastersuse Avatar asked Dec 03 '25 09:12

mastersuse


1 Answers

Try this:

$("#xyz").attr('disabled',true);

$('#xyz').selectpicker('refresh');

You should refresh the selectpicker after any updates in it.

like image 168
Kulshreshth K Avatar answered Dec 05 '25 00:12

Kulshreshth K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!