Reputation: 1249
I have five dropdownlists on the form. I want that if user select something from one of dropdownlists, the other ones should be unselected. User can select something from just one dropdownlist.When he select something,selected value of other dropdownlists should be unselected. I'm using jquery
@foreach (var lay in Model.EventLayouts)
{
<li>
<select class="layoutSelect" layoutname="@lay.Name" layoutId="@lay.LayoutID" moderation="@lay.Moderation.ToString().ToLower()" selectedVal="0">
<option value="0">@PageResources.Quantity</option>
<option value="1">1</option>
</select>
</li>
}
Upvotes: 0
Views: 1132
Reputation: 20418
Try this way
$(document).on('change', '.layoutSelect', function () {
if ($(this).find('option').is(":selected")) {
$('.layoutSelect').not($(this)).val("");//val('0');
}
});
Upvotes: 2
Reputation: 28523
Assuming that both dropdown has same class="layoutSelect"
and unselect value="0"
, try below jQuery :
$('.layoutSelect').change(function(){
$('.layoutSelect').not(this).val('0');
});
Upvotes: 2
Reputation: 62498
If you are trying to reset the other drop-downs but not the one which is changed, by adding same class on all drop-down you can do like this:
$(".layoutSelect").change(function(){
$(".layoutSelect").not(this).val(0);
})
Upvotes: 1