Forums

ASP

This topic is locked

comparing values

Posted 19 Apr 2002 12:14:50
1
has voted
19 Apr 2002 12:14:50 Tom Ka posted:
Hello

Problem:
I have two recordsets. with one I'm writing via while...wend all the values of an table into my page. the same with the other one which holds only values which are also in the first recordset (the values are only numeric).
At the end, my page must have for each record in the first set a checkbox - and the ID of the record will be assigned to the checkbox value (html). Now I want to compare and do the following: when the ID of an record of the first set is also somewhere in the other set, I want to write the attribut CHECKED into the checkbox html tag.
so it looks like this ( [ ] = checkbox)

[ ] sometext1
[ ] sometext2
[ ] sometext3
[ ] sometext4

If there are the IDs of 2 and 3 in the second set the html output should look like this:

[ ] sometext1
[x] sometext2
[x] sometext3
[ ] sometext4

this coding must be done in the asp-page and not as part of a DB-Operation...

May I can do this when I write the values of set2 into an array and then make something like IF valueset1 IN ARRAY then strAttribut = CHECKED
?????
Some idea how such a code could look like???

Thanks for help!!!!!
Tom

Replies

Replied 19 Apr 2002 13:12:01
19 Apr 2002 13:12:01 Owen Eastwick replied:
Try something like:


In the VBScript after the recordset code
<%
' Create a String from the values in the first recordset
varString = ""
While Not Recodset1.EOF
varString = varString + " " + Recordset1.Fields.Item("FieldName".Value
Recordset1.MoveNext()
Wend
%>

Then in the HTML portion of the page:

<input type="checkbox" name="checkbox" value="checkbox" <% If InStr(varString, (CStr(Recorset2,Fields.Item("FieldName".value))) <> 0 Then %>checked<% End If %>>

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 19 Apr 2002 14:12:08
19 Apr 2002 14:12:08 Tom Ka replied:
OOOps
There is some Issue:

When there is the value 11 in the recordset2 then it checks also a checkbox when the recordset1 have as ID the 1 (as well as within all IDs above 9 because they contain the 1)

can I compare exactly so that 1 <> 11 ?
I tried to remove cstr but of course it does the same

Tom
But in princip it works and brought me a step forward!

Edited by - mmtom on 19 Apr 2002 14:40:29
Replied 19 Apr 2002 17:21:49
19 Apr 2002 17:21:49 Owen Eastwick replied:
Aaah, yep that would happen. How about:

In the VBScript after the recordset code
<%
' Create a String from the values in the first recordset
varString = ""
While Not Recodset1.EOF
varString = varString + "*" + Recordset1.Fields.Item("FieldName".Value + "* "
Recordset1.MoveNext()
Wend
%>

So now we have a list like this *1* *2* *3* *4* .......etc.

Then in the HTML portion of the page:

<input type="checkbox" name="checkbox" value="checkbox" <% If InStr(varString, (CStr("*" & Recorset2,Fields.Item("FieldName".value & "*")) <> 0 Then %>checked<% End If %>>

So we will look for mathches *1*, *2* .....*10*, *11* - should cure the problem.

Regards

Owen.

Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo

Edited by - oeastwick on 19 Apr 2002 17:22:48
Replied 19 Apr 2002 22:44:08
19 Apr 2002 22:44:08 Tom Ka replied:
Yep - That works!
I thought, it wouldn't but it did!!!

PS: The Advanced Search Tutorial is very good Stuff!!!

Thanks a lot!

Reply to this topic