Remove duplication Jquery code is not working on all dropdown on my MVC form

  javascript, jquery, model-view-controller

I am using a jquery code found on Stakeoverflow to remove duplication value in the dropdown. my problem is the jquery code worked for the first dropdown but will not work for the second dropdown any help will be welcome

1st dropdown

<select id="AssetStoredWhere" name="AssetStoredWhere" class="form-control js-example-disabled-results 
     select">
   <option value="@ViewBag.AssetStoredWhere">@ViewBag.AssetStoredWhere</option>
   <option value="UK">UK</option>
   <option value="EU">EU</option>
   <option value="Worldwide">Worldwide</option>

</select>

2bd Dropdown

<select asp-for="Dpiaavailable" id="Dpiaavailable" name="Dpiaavailable" class="form-control js- 
   example-disabled-results select">
   <option value="@ViewBag.Dpiaavailable">@ViewBag.DpiaavailableValue</option>
   <option value="False">No</option>
   <option value="True">Yes</option>
</select>

Jquery code

var seen = {};
jQuery('.select').children().each(function () {
    var txt = jQuery(this).attr('value');
    if (seen[txt]) {
        jQuery(this).remove();
    } else {
        seen[txt] = true;
    }
});

Source: Ask Javascript Questions

LEAVE A COMMENT