Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable bootstrap dropdown list

I made a dropdown list using bootstrap.Dynamically I want to disable and enable the dropdown list.

html code:

  <div class="span3 offset1">
        <select name="primary" class="select-block" id="select_alert" style="display: none;">
            <option "selected"="">Choose Alert T</option>                         


    <option value="T1">T1</option>

    <option value="T2">T2</option>

    <option value="T3">T3</option>

    <option value="T4">T4</option>

</select>
<div class="btn-group select select-block">
  <i class="dropdown-arrow dropdown-arrow-primary"></i>
  <button class="btn dropdown-toggle clearfix btn-primary" data-toggle="dropdown" id="select_alert">
    <span class="filter-option pull-left">Choose Alert T</span>&nbsp;
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu dropdown-primary" role="menu">
    <li rel="0" class="selected">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">Choose Alert T</span>
      </a>
    </li>
    <li rel="1">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T1</span>
      </a>
    </li>
    <li rel="2">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T2</span></a>
    </li>
    <li rel="3">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T3</span>
      </a>
    </li>
    <li rel="4">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T4</span>
      </a>
    </li>
  </ul>
  </div>
</div>

some times I want to disable and sometimes I want to enable.So How can I do this. In this I have 2 more dropdown elemnts.All are placed in singlw div tag.Here I didn't mention that div tag id name.I just putted single dropdown element code.

like image 303
user2873816 Avatar asked Jan 20 '26 00:01

user2873816


1 Answers

Yes, by jquery you can get this:

Here is the example:

http://jsfiddle.net/jV7ye/

$(document).ready(function() {
    $("#chkdwn2").click(function() {
       if ($(this).is(":checked")) { 
          $("#dropdown").prop("disabled", true);
       } else {
          $("#dropdown").prop("disabled", false);  
       }
    });
});

UPDATED JS CODE as per your need:

$(document).ready(function() {

        if(!$("#chkdwn2").is(":checked"))
        {
            $("#dropdown").prop("disabled",true);
        }

        $("#chkdwn2").click(function() {
           if ($(this).is(":checked")) { 
              $("#dropdown").prop("disabled", false);
           } else {
              $("#dropdown").prop("disabled", true);  
           }
        });
    });

Replace dropdown id with your id. Thanks

like image 95
JERRY-the chuha Avatar answered Jan 22 '26 13:01

JERRY-the chuha



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!