I am trying to develop a feature which involves 2 select list items.
Flow goes something like this,
- There are two list items (identical) with the same list items
- When I select an option from
Main Tags
list, the same option inSub Tags
list should get disabled. For example, If I selectTag 1
from theMain Tags
list thenTag 1
from theSub Tags
list should get disabled. (Toggle effect: when I select other options from the 1st list, then previously disabled item should b enabled) Sub Tags
list is multiple selection. Here selected values gets displad nex to it as a tags with delete tag option on it (Which is working in my code). But When user change the option fromMain Tags
list and the same thing is already been displayed here as aSelected tags
section then it should get removed fromselected tags
section andSub Tags
list (Which is disable at this point) as well.
Basic idea is not to have same option under both Main Tags
and Sub Tags
Hope my question is clear.
Here is my current code,
$(function () {
$("#tagSel").change(function () {
$this = $(this);
$("#tags").append('<span id="' + $this.val() + '"> ' + $this.find('option:selected').text() + ' <a href="#">×</a></span>');
$this.find('option:selected').prop("disabled", true);
});
$("#tags").on("click", "span a", function () {
$("#tagSel option[value='" + $(this).parent().attr("id") + "']").prop('disabled',null);
$(this).parent().remove();
$("#tagSel_main").append('<i ></i>')
});
});