I don't understand the bit about the textareas. What's with the
multiple textareas?
You haven't shown us any HTML, so we have to guess!
I thought we were talking about an autocomplete text input here,
not textareas.
Are you wanting a separate text input for each name?
Actually, avoiding duplicates has nothing to do with your list you
get from the server. You don't need to know the names, unless you
want to limit to THAT list. That's a completely separate problem
from avoiding duplicates.
Just add names to an array. Check first to see if the name is
already there.
If you use an object instead of an array, it's even easier.
var
selectedNames = {};
Then to add a name:
// I used a
static example here, you would get the name from the input
var name =
'John Smith';
if
(selectedNames[name]) {
alert("You
already added this name!");
} else {
selectedNames[name] = true;
}
"true" is just an
arbitrary value. It can be anything (other than false or undefined or 0!)