saifuddinazhar
4/12/2018 - 4:40 PM

UI - Select

select, option, find selected, dropdown

//find selection
$('#selectDailyStocktakeSetting').find(":selected").val();
 
$('#mySelect').find('option').not(':first').remove();
//To remove all the options except one with a specific value, you can use this:

$('#mySelect').find('option').not('[value=123]').remove();
//This would be better if the option to be added was already there.
<!--Select example-->
<select class="form-control" data-val="true" id="selectDailyStocktakeSettingForPrint" name="QuantityUnitID">
    <option value="">@UIResources.DropdownSelect</option>
    @foreach (var dailyStocktakeSetting in ViewBag.DailyStocktakeSettings) {
        <option value="@dailyStocktakeSetting.ID">@dailyStocktakeSetting.Name</option>
    }
</select>