I'm trying to find the best way to add selected items from one combobox to another. The trick is I only want to add items to the destination list that don't already exist. Currently the process I use is rather ugly and does not work as I would expect.
$('#addSelectedButton').click(function() {
var previousOption;
$('#sourceList option:selected').appendTo('#destinationList');
$('select[name=destinationList] option').each(function () {
if (this.text == previousOption) $(this).remove();
previousOption = this.text;
});
});
The problem I'm having is that the appendTo method acts as more of a move rather than an add. Then there's the problem of removing the duplicates, which works in this this example, but I can't help but think there's a better way.
Any assistance would be greatly appreciated.
Thanks,