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