Hi all i have a problem with a script. I need to check if a value exist into an array, is this value is new i add it to the array otherwise i return false from a
function.
function copia()
{
cap1 = document.getElementById('cap_da_assegnare');
//eseguo un ciclo per trovare gli elementi selezionati
for (i = 0; i < cap1.length; i++) {
if (cap1.options[i].selected) {
//recupero id e valore letterale
v = cap1.options[i].value;
t = cap1.options[i].text;
//recupero l'id della select di destinazione
if (addItem(v)) {
cap2 = document.getElementById('cap_assegnati');
len = cap2.length;
cap2[len] = new Option(t, v, false);
}
}
}

aggiornaCap();
}


The function addItem(v) return true if the value is a new element otherwise false.
function addItem(val)
{
duplicated = false;

for (i = 0; i < myVector.length; i++) {
if (myVector[i] == val) {
duplicated = true;
}
}

if (duplicated == true) {
return false;
} else {
myVector[myVector.length] = val;
return true;
}
}

The script work as well but when i delete from the myVector element
and later i try to put new element the browser crash.

This is the function delItem
function delItem(val)
{
for (i = 0; i < myVector.length; i++) {
if (myVector[i] == val) {
myVector.splice(i, 1);
}
}
}

I'm not an expert on js i hope that my english is enough clearly to understand
my problem.
Thanks in advance.