How can i remove duplicates on a multiple select option while maintaining the "selected" attribute.
I have the following in my codes
<select class="colab-select" name="colab[]" multiple>
<option value="1" selected>Dexter</option>
<option value="2" selected>James</option>
<option value="3">Mary</option>
<option value="1">Dexter</option>
<option value="2">James</option>
<option value="3">Mary</option>
</select>
I have these in my jquery for removing the duplicates but when it removes the duplicate, it would "unselect" James
but Dexter
would still be selected.
var a = new Array();
$(".colab-select").children("option").each(function(x){
test = false;
b = a[x] = $(this).val();
for (i=0;i<a.length-1;i++){
if (b ==a[i]) test =true;
}
if (test) $(this).remove();
});
Any ideas why is this happening?