View Full Version : Two select boxes, remove the duplicates?

08-23-2002, 04:57 PM
Does anyone have an elegant way of removing duplicate elements from select boxes that have their size attribute set to 1?

I have two HTML select tags on my webpage.

SelBox2 must not have the same elements as SelBox1. They are both loaded from the database and duplicate values can occur. If they do they must be detected and removed.

I can't figure out how to do this.

08-23-2002, 05:35 PM
Um, I imagine something close to this
function deleteDupes(sel1ID, sel2ID) {
var sel1 = document.getElementById(sel1ID);
var sel2 = document.getElementById(sel2ID);

for (var i=0; i<sel1.length; i++)
for (var j=0; j<sel2.length; j++)
if (sel2.options[j].value == sel1.options[i].value)