I set up my jQuery like so.
It successfully lets me pick an option only once throughout the 3 dropdowns.
However, if I remove a dropdown (use the convenient button), an option is forever disabled (greyed out).
You’ll see what I mean. First, ensure that it works and you can not select the same option more than once.
Now, remove and notice that one has been disabled, and it can never be selected again.
I don’t know why it is forever greying out my option? It seems to keep picking it up when making the selectedIndexes array.
Does anyone know how to get around this problem?
I made some changes to your code, you can see them here. It also did not work for my in the beginning, but now it works, I think, as expected. If you have questions, just comment 🙂
Here we go:
Redeclare the
$selectsarray once you remove an element. The reference to the element is still in the array, so when you later compute the selected indexes, it will still be there!In the select click handler, use
nth-childinstead ofeq. The former one will select alloptions that are theith child of their parents. Whereaseqwill only select theith element from the set of matched elements (i.e. it will only return one element). Note that the index ofnth-childis one-based.