This is what I am trying to do: I present the user with a textarea and he must enter some domains, if he enters the same domain twice (a duplicate) I want to delete the dupes.
So far I have come till the part where I can find the dupes, this is the code I am using:
function check_if_already_in_the_list___manual_textbox()
{
var therows=0;
var thetext = document.forms[0].text.value;
var newtext = thetext.split("\n");
therows+=newtext.length;
var i;
var match_counter=0;
for(i=0;i<newtext.length;i++) // first iterate over the number of items
{
for(j=0;j<newtext.length;j++) // second, start a second loop to compare each other
{
if(newtext[j].toLowerCase()==newtext[i].toLowerCase())
{
match_counter++;
}
if(match_counter >=2) // Found dupe!
{alert("Matched:"+newtext[j]+" "+newtext[i]+" Counter"+match_counter);
match_counter=0;}
}
alert("Match counter:"+match_counter+ " D:"+newtext[i]);'
match_counter=0;
}
//alert(""+match_counter);
return match_counter;
}
Any suggestions to do this better would be most appreciated, also I have no idea how to take out the dupes :(
Googling I see that I probably have to use "splice" but not really sure.
Thanks in advance!
R
(P.S Sorry the format looks weird, but that happened when I pasted in the code)