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');
}
$('#dropDownId'). attr('disabled');
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.
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"/>
You can get the :selected
option then check its prop()
if($('#dropdown option:selected').prop('disabled') == true){
//Selected option is disabled
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With