disable dropdown options based on the previously selected dropdown values using jquery or javascript? -


i have 3 dropdowns same options. want is, when selecte option dropdown, same option other 2 dropdowns disabled, except first 1 (the option 'select one').

for using following logic, here when 1 dropdown selected 1 value instead of disabling selected value remaining 2 dropdowns, disabling of these 3 dropdowns don't want. disabling of value should happen remaining ones not current dropdown.

how can this?

<select class="form-control positiontypes">     <option value="">select one</option>     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option>     <option value="5">5</option>     <option value="6">6</option>     <option value="7">7</option> </select>  <select class="form-control positiontypes">     <option value="">select one</option>     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option>     <option value="5">5</option>     <option value="6">6</option>     <option value="7">7</option> </select>  <select class="form-control positiontypes">     <option value="">select one</option>     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option>     <option value="5">5</option>     <option value="6">6</option>     <option value="7">7</option> </select> 
$("select.positiontypes").change(function () {     $("select.positiontypes option[value='" + $(this).data('index') + "']").prop('disabled', false);     $(this).data('index', this.value);     $("select.positiontypes option[value='" + this.value + "']:not([value=''])").prop('disabled', true); }); 

here fiddle link https://jsfiddle.net/3pfo1d1f/4/

do this: https://jsfiddle.net/sandenay/3pfo1d1f/7/

$("select.positiontypes").change(function () {     $("select.positiontypes option[value='" + $(this).data('index') + "']").prop('disabled', false); //reset others on change everytime     $(this).data('index', this.value);     $("select.positiontypes option[value='" + this.value + "']:not([value=''])").prop('disabled', true);     $(this).find("option[value='" + this.value + "']:not([value=''])").prop('disabled', false); // not apply logic current 1 }); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -