Compare Loop

1. Senior Member
Join Date
Dec 1969
Posts
114

## Compare Loop

Trying to write a loop to compare input data for duplicates. <BR>i.e. If q1a = q1b OR q1a = q1c THEN<BR><BR>

2. Mike Shaffer Guest

## RE: Compare Loop

Hi Larry,<BR><BR>I noticed that you have posted this a couple of times today, so I thought I&#039d try to help. Unfortunately, there is no easy answer given the information you&#039ve provided.<BR><BR>There are many ways to do what you are asking, (for example, if the items you are comparing are in arrays, the you could use nested loops to compare them, etc.)<BR><BR>Give us some more detail, and perhaps some of your code, and we can help.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
114

## RE: Compare Loop

&#060;%<BR> q1a = Request.Form("q1a")<BR> q1b = Request.Form("q1b")<BR> q1c = Request.Form("q1c")<BR> q1d = Request.Form("q1d")<BR> q1e = Request.Form("q1e")<BR> q1f = Request.Form("q1f")<BR> q1g = Request.Form("q1g")<BR> q1h = Request.Form("q1h")<BR> q1i = Request.Form("q1i")<BR> q1j = Request.Form("q1j")<BR><BR> If q1a = q1b OR q1a = q1c Then<BR><BR> Response.Redirect "page1error.asp" <BR>END IF<BR>%&#062;<BR>&#060;html&#062;<BR>&#060;head&#0 62;

4. Joseph Price Guest

## RE: Compare Loop

Hi Larry-<BR><BR>I would put all of your elements in an array and then look through comparing each to each other. That should do the trick.<BR><BR>- Joe Price<BR>jkprice@gte.net

5. Mike Shaffer Guest

## RE: Compare Loop

There are SO MANY ways to do this, but most are truly fugly compared to using arrays (instead of simple variables). I would recommend that you do so. :)

6. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## Client side check

Since the data comes from a form you could use client side script to check, i.e:<BR><BR>&#060;SCRIPT Language=Javascript&#062;<BR>function test(){<BR>var FoundDuplicates = 0;<BR>var BoxCount = MyForm.elements.length;<BR>for (i=0;i&#060;BoxCount;i++){<BR>for (iA=0;iA&#060;BoxCount;iA++){<BR>if ((MyForm.elements[i].value==MyForm.elements[iA].value)&&i!=iA){<BR> FoundDuplicates = 1;<BR>}<BR>}<BR>}<BR>if (FoundDuplicates){<BR> alert("form contains duplicated data");<BR>}else{<BR> MyForm.submit();<BR>}<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;FORM NAME=MyForm ACTION="MyAsp.asp"&#062;<BR> &#060;input type="text" name="q1a" value="test1"&#062;<BR> &#060;input type="text" name="q1b" value="test2"&#062;<BR> &#060;input type="text" name="q1c" value="test3"&#062;<BR> &#060;input type="text" name="q2a" value="test4"&#062;<BR> &#060;input type="text" name="q3a" value="test2"&#062;<BR> &#060;input type="text" name="q4a" value="test5"&#062;<BR> &#060;input type="text" name="q5a" value="test6"&#062;<BR> &#060;input type="text" name="q6a" value="test7"&#062;<BR> &#060;input type="text" name="q7a" value="test8"&#062;<BR> &#060;input type="button" onClick="test()" value="OK"&#062;<BR>&#060;/FORM&#062;<BR><BR>

7. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## Server side check

It occured to me that you do this in ASP, note that the sending form must have METHOD=POST.<BR><BR>&#060;%<BR>For i = 1 To Request.Form.Count<BR> For iA = 1 To Request.Form.Count<BR> If Request.Form(i)(1) = Request.Form(iA)(1) AND i&#060;&#062;iA Then<BR> FoundDuplicates = 1<BR> End If<BR> Next<BR>Next<BR><BR>If FoundDuplicates = 1 Then<BR> Response.write "Found duplicates"<BR>Else<BR> Response.write "No duplicates"<BR>End If <BR>%&#062;

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•