1

I have 2 drop-down like below:

<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id ="1st-dd">
   <option value="23" disable_child= "y" class="disableDropdown">No Pocket</option>
   <option value="24" disable_child= "n" selected="selected"
 class="disableDropdown">1 Pocket</option>
   <option value="25" disable_child= "n" class="disableDropdown">2 Pocket</option>
 </select>  
</div>

<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id = "flap-drop">
    <option value="26">No Flap</option>
    <option value="27" selected="selected">Flap Pocket</option> 
 </select> 
</div>

What I want is when I select No Pocket in dropdown1, disable both the options of dropdown 2. And enable If any other option is selected in dropdown 1.

Here's what I am trying.

$(".disableDropdown").click(function(){
 //alert($(this).attr("disable_child"));
  if( $(this).attr("disable_child") == "y") 
  {
   $("#flap-drop").attr("disabled",true);
  }
 else{
   $("#flap-drop").attr("disabled",false);
  } 
 });

What's wrong here?

Here's the fiddle for the same.

3 Answers 3

3

You can use prop():

$('option').prop('disabled', 'disabled')
Sign up to request clarification or add additional context in comments.

Comments

2

$("#1st-dd").change(function() {
    $("#flap-drop").attr("disabled", this.value=="23"); 
    // or $("#flap-drop").toggle(this.value!="23");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id="1st-dd">
    <option value="23" disable_child="y" class="disableDropdown">No Pocket</option>
    <option value="24" disable_child="n" selected="selected" class="disableDropdown">1 Pocket</option>
    <option value="25" disable_child="n" class="disableDropdown">2 Pocket</option>
  </select>
</div>

<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id="flap-drop">
    <option value="26">No Flap</option>
    <option value="27" selected="selected">Flap Pocket</option>
  </select>
</div>

Try it this way. Instead of click i used change and compare the values same as you did

4 Comments

when I select No pocket in dropdown 1, both the options are getting disabled all right, but even then the dropdown looks like we can still do some select. So Is there anyway that the whole select option gets disabled?
yes remove the children from the selector when i read you question that is how i understand what you wanted i will update
Please drop the if and the option:selected and do "disabled",this.value=="23")
@mplungjan i can be a completely different answer my approach is to use the OP previous code and did some modification. pls feel free to update the answer if you think it needs some revision.
0

$("#1st-dd").change(function() {
    $("#flap-drop").attr("disabled", this.value=="23"); 
    // or $("#flap-drop").toggle(this.value!="23");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id="1st-dd">
    <option value="23" disable_child="y" class="disableDropdown">No Pocket</option>
    <option value="24" disable_child="n" selected="selected" class="disableDropdown">1 Pocket</option>
    <option value="25" disable_child="n" class="disableDropdown">2 Pocket</option>
  </select>
</div>

<div class="col-sm-2 uno_part_wrapper">
  <select class="form-control switcher" id="flap-drop">
    <option value="26">No Flap</option>
    <option value="27" selected="selected">Flap Pocket</option>
  </select>
</div>

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.