I want to hide option from previous selected dropdown but my solution only works for two dropdown list.
This means that when I come to third dropdown list it will not display selected option from second dropdown list which is ok but it will display selected option from first one.
So, as I understand, methods I'm using overrides the last one that's why it not works.
Here is my select lists:
<select id="select1"
onchange="getSelectValue(this.value)"
asp-for="AssignedGroups.GroupMemberId1"
asp-items="@(new SelectList(Model.Agents,"Agent_Id","Agent_Id"))"
class="form-control">
<option hidden selected></option>
</select>
<select id="select2"
onchange="getSelectValue2(this.value)" asp-
for="AssignedGroups.GroupMemberId2"
asp-items="@(new SelectList(Model.Agents,"Agent_Id","Agent_Id"))"
class="form-control" >
<option hidden selected></option>
</select>
<select id="select3"
onchange="getSelectValue3(this.value)" asp-
for="AssignedGroups.GroupMemberId3"
asp-items="@(new SelectList(Model.Agents, "Agent_Id", "Agent_Id"))"
class="form-control">
<option hidden selected></option>
</select>
And my script: strong text
function getSelectValue(select1) {
$("#select2 option[value='" + select1 + "']").hide();
$("#select2 option[value!='" + select1 + "']").show();
$("#select3 option[value='" + select1 + "']").hide();
$("#select3 option[value!='" + select1 + "']").show();
}
function getSelectValue2(select2) {
$("#select1 option[value='" + select2 + "']").hide();
$("#select1 option[value!='" + select2 + "']").show();
$("#select3 option[value='" + select2 + "']").hide();
$("#select3 option[value!='" + select2 + "']").show();
}
function getSelectValue3(select3) {
$("#select1 option[value='" + select3 + "']").hide();
$("#select1 option[value!='" + select3 + "']").show();
$("#select2 option[value='" + select3 + "']").hide();
$("#select2 option[value!='" + select3 + "']").show();
}