Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Duplicate Records 1

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
An HTML Form has two textboxes. Suppose a user enters 23, 45, 68, 99 in the 1st textbox & in the 2nd textbox, he enters 54, 68, 78, 94. Note that in the 2 textboxes, 68 is common. What I want is under such circumstances, 68 should automatically get deleted from the 2nd textbox (as it is already present in the 1st textbox). How do I do this?

Thanks,

Arpan
 
YOu keep coming up with fun ones. Will the values always be numeric? Will they always be separated by a comma?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Can they enter "68" (or whatever) a number of times in the first box, or do you want that restricted too?
 
"Fun" ones or the "funny" ones?? What do you mean by "fun" ones? Anyway w.r.t. your 2 doubts, the answers of both the doubts is yes i.e. the values will always be numeric & will always be seperated by a comma? Any other doubts?? I will be happy to clarify them.

Thanks,

Regards,

Arpan
 
<script>
function checkVals(){
field1 = document.getElementById(&quot;in1&quot;)
field2 = document.getElementById(&quot;in2&quot;)

arr1 = field1.value.split(&quot;,&quot;)
arr2 = field2.value.split(&quot;,&quot;)

for (x=0; x<arr1.length; x++){
for (y=0; y<arr2.length; y++){
if(arr1[x] == arr2[y]){
arr2.splice(y,1)
}
}
}
field2.value = arr2
}
</script>

<input id=&quot;in1&quot;>
<input id=&quot;in2&quot;>
<input type=button onClick=&quot;checkVals()&quot; value=&quot;Check For Duplicates&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Whatever number it is, it will appear only once in the 1st textbox. But it can appear any number of times in the 2nd textbox. Is such cases, all the &quot;68&quot;s should be deleted from the 2nd textbox.
 
Thanks wolf for your code. It works properly but still a problem exists. If &quot;68&quot; (as per the e.g. I had given) is the 1st number in either the 1st or the 2nd textbox, it does not get deleted from the 2nd textbox (though 68 is present in the 1st textbox). Any workaround to fix this??

Regards,

Arpan
 
hmm- I can't duplicate consistantly - but an extra space could be causing the problem. Fix it like this...

<script>
function checkVals(){
field1 = document.getElementById(&quot;in1&quot;)
field2 = document.getElementById(&quot;in2&quot;)

arr1 = field1.value.split(&quot;,&quot;)
arr2 = field2.value.split(&quot;,&quot;)

for (x=0; x<arr1.length; x++){
for (y=0; y<arr2.length; y++){
if(parseInt(arr1[x]) == parseInt(arr2[y])){
arr2.splice(y,1)
}
}
}
field2.value = arr2
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top