I have two jQuery EasyUI Combobox in which I have a list of items. Each combobox has exactly the same list of items. What I’m trying to do is that when I select one item from the first combobox, I want the selected item to be unavailable on the second combobox (and vice versa). I did this by using the replaceWith() method of jQuery like:
$('#old_element').replaceWith('#new_element');
That works fine as you can see from that DEMO. But the problem I have is that, when an item is replaced in a combobox, I can no longer click on the replaced item. For example, if you select Java in combobox1, Java will be removed from combobox2 (you’re left with only Perl and Ruby), now if you select Ruby in combobox1, it will replace Ruby in combobox2 by the old value of combobox1 (which is Java), but now if you try to click on Java in combobox2, it does not work (I cannot click). Can anybody tell me how I can solve this situation. There seems to be also some empty divs that are added to the list when I replace an element from that list by another one. Any idea how can I resolve these issues please?
You can view the code in THAT DEMO
You are doing it the hard way. I will make two assumptions for simplicity to explain how you can achieve that without screwing up the low level markup which you shouldn’t be using.
Move your
datafrom the markup to JavaScript.I will assume both comboboxes use the same
data.With this into account you can use the
dataparameter to initialize the comboboxes. And, in theonchangeevent then filter out the matches in the partner combobox set the filtered content using theloadDatamethod.See it here.
UPDATE
An alternative without modifying the HTML layout.
There you go.