I have four dropdowns and four options, all four dropdowns have same options. I am trying to remove options in other three dropdowns if user selects one option from current dropdown. If user changes again with a new value, new value option should remove and old value should populate again in other dropdowns. I did something but it is not working as expected.
Refer to the following jsFiddle(Updated): http://jsfiddle.net/ruq1jb0c/5/
$('.inputcontrol').change(function() { var fields = ['Employee', 'Status', 'State', 'Supervisor']; var value = $(this).val(); $('.inputcontrol').not(this).find('option').each(function() { if ($(this).val() == value) { $(this).remove() } }); $('.inputcontrol').each(function() { for (var i = 0; i < fields.length; i++) { if (fields[i] != value) { if ($(this).find("option[value=" + fields[i] + "]").length == 0) { $(this).append("<option value=" + fields[i] + ">" + fields[i] + "</option>"); } } } }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="field1" class="inputcontrol"> <option value="Employee">Employee</option> <option value="Status">Status</option> <option value="State">State</option> <option value="Supervisor">Supervisor</option> </select> <br><br> <select id="field2" class="inputcontrol"> <option value="Employee">Employee</option> <option value="Status">Status</option> <option value="State">State</option> <option value="Supervisor">Supervisor</option> </select> <br><br> <select id="field3" class="inputcontrol"> <option value="Employee">Employee</option> <option value="Status">Status</option> <option value="State">State</option> <option value="Supervisor">Supervisor</option> </select> <br><br> <select id="field4" class="inputcontrol"> <option value="Employee">Employee</option> <option value="Status">Status</option> <option value="State">State</option> <option value="Supervisor">Supervisor</option> </select>