Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if prop of selected dropdown is disabled

I'm having trouble to check if the selected option of a dropdown is disabled.

The user has the possibility to choose a option and then select a time range, after the time selection, all the options not available in this range will be set to disabled. If the previous selected value was also disabled there must be an alert.

I was thinking of something like this:

if($('#dropdown').val().prop('disabled',true)){
alert('not possible'); 
}
like image 641
nogato Avatar asked Jan 03 '17 11:01

nogato


People also ask

How check dropdown is disabled or not in jquery?

$('#dropDownId'). attr('disabled');

How to disable option in dropdown HTML?

We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element. A disabled drop-down list is un-clickable and unusable.


2 Answers

Use this:

if($('#dropdown').find(':selected').prop('disabled')){
  alert('not possible'); 
}

$('input').change(function(){
  if($(this).val()>50){
    $('select option:first-child').prop('disabled',true);
  }
  if($('select').find(':selected').prop('disabled')){
      alert('not possible'); 
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>
<input type="range"/>
like image 150
Mihai Alexandru-Ionut Avatar answered Sep 27 '22 21:09

Mihai Alexandru-Ionut


You can get the :selected option then check its prop()

if($('#dropdown option:selected').prop('disabled') == true){
    //Selected option is disabled
}
like image 23
Satpal Avatar answered Sep 27 '22 22:09

Satpal