View Single Post
  #1 (permalink)  
Old 11-12-09, 09:50 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Preventing dupes in javascript array?

I have a form that lets people copy items from one select list to another, but I want to prevent them from putting duplicate items into the second list. In other words, they can pick as many items from the first list as they want, but they can't pick and add the same one twice.

In the code below, what would be the best way to prevent adding duplicate items to the "destList.options" array?

HTML Code:
// Populate  destination with  items from new array
for ( var j = 0; j < newDestList.length; j++ ){

    if ( newDestList[ j ] != null ){

	      destList.options[ j ] = newDestList[ j ];

    }

}
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote