Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Hastings, East Sussex
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Two select boxes, remove the duplicates?

    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.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Um, I imagine something close to this
    Code:
    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)
    				sel2.removeChild(sel2.options[j]);
    	}


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •