Hi every body, i'm a newbie in javascript, so i need all your help

i have a javascript like this:

<script type="text/javascript">

    function validate(target, e){

        var id = e.dataTransfer.getData('div');
        var clone = document.getElementById(id).cloneNode(true);
        var allValues = []; 
        for (i=0; i<clone.length; i++)
            {
             if (clone[i].value != "")
                {
                 allValues[i] = clone[i].value.toLowerCase();
                }
            }
        allValues.sort();       
        var uniqueValues = [];      
        var idx = 0;
        var prevValue = allValues[0];
        var currValue = allValues[0];
        for (i=0; i<allValues.length; i++)
            { 
             currValue = allValues[i];
             if (currValue != prevValue){idx++;}
             uniqueValues[idx] = currValue;
             prevValue = currValue;
            }
        if (uniqueValues.length != allValues.length)
            {

              e.preventDefault();
              clone.parentNode.removeChild(clone);
             alert('Cannot submit duplicate entries');
             return false;
            }
        else    {
             alert(clone.id);
             e.preventDefault();
             target.appendChild(clone); 
             return true;
            }
    }

</script>

So i'm trying to do ondrop function(validate), so when i drop something for the first time,the validate function will run and drop the div value. But for the second time and so on, if i dropped the same div value i want it to alert duplicate and remove that div element, but i'm unsuccessfull in detecting the duplicate div.Can anyonr tell me whats wrong with my code?
Firstly Thanks for the help

Your best bet is to check for duplicates before you print them to the list. If they are always sorted (as it appears in your example), then you can easily do this just by keeping track of what was the last value you used. Make sure the current value does not match, then display it and assign it as the new last value

commented: thx i will try your suggestion +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.