Jomol John Jomol John - 1 month ago 11
jQuery Question

Disable options in drop-down if selected value matches using jquery

I have a drop-down list which contains duplicated values. Now i want to disable the options, which matches to the selected value.

Answer

using .prop('disabled',true); element can be disabled. Please check below snippet to get idea how to make all other options with same value can make disabled.

$('#duplicate').on('change',function(){
$(this).find('option').prop('disabled',false);  
$(this).find('option[value="'+$(this).val()+'"]').prop('disabled',true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="duplicate">
  <option value="">select</option>
  <option value='1'>1</option>
  <option value='2'>2</option>
  <option value='1'>1</option>
  <option value='1'>1</option>
  <option value='3'>3</option>
  <option value='4'>4</option>
  <option value='3'>3</option>
</select>