How do I retreive my second value?

Hi experts,

In my script I construct a part of a form based on some fields from my database:

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT MSVT_handelingen.*, MSVT_categorieen.categorie AS categorienaam, MSVT_categorieen.complexiteit FROM MSVT_handelingen INNER JOIN MSVT_categorieen ON MSVT_handelingen.categorie=MSVT_categorieen.ID", CS, 3, 4
         While Not rs.EOF
                  Response.Write "<tr><td align=""center""><input type=""checkbox"" value=""" & rs("volgorde") & """ name=""checkbox"" /></td><td align=""center"">"& rs("volgnummer") & "</td><td>" & rs("handeling") & "</td><td align=""center"">"& rs("normtijd")&"</td><td align=""center""><input size=""5"" type=text name=""tijd-"& rs("volgorde") &"""></td></tr>"& vbCrLf
            rs.MoveNext
         Wend
rs.Close
Set rs = Nothing
%>

This resulds in html output like this:
<tr><td align="center"><input type="checkbox" value="1" name="checkbox" /></td><td align="center">1</td><td>inzetten/starten medicatietoediening via een pomp (morfine, dormicum)</td><td align="center">60</td><td align="center"><input size="5" type=text name="tijd-1"></td></tr>
<tr><td align="center"><input type="checkbox" value="2" name="checkbox" /></td><td align="center">2</td><td>het toedienen of aansluiten van intraveneuze medicatie</td><td align="center">30</td><td align="center"><input size="5" type=text name="tijd-2"></td></tr>
<tr><td align="center"><input type="checkbox" value="3" name="checkbox" /></td><td align="center">3</td><td>toedienen te prepareren medicatie via rechtstreekse intraveneuze injectie of via een lopend infuus</td><td align="center">20</td><td align="center"><input size="5" type=text name="tijd-3"></td></tr>
<tr><td align="center"><input type="checkbox" value="4" name="checkbox" /></td><td align="center">4</td><td>inbrengen  perifere catheter</td><td align="center">30</td><td align="center"><input size="5" type=text name="tijd-4"></td></tr>
<tr><td align="center"><input type="checkbox" value="5" name="checkbox" /></td><td align="center">5</td><td>aanwezigheid gedurende de toediening van medicatie, bv antibiotica of chemo en aansluiten en afkoppelen </td><td align="center">60-180</td><td align="center"><input size="5" type=text name="tijd-5"></td></tr>

As you can see I have selectbox and a text input in every line.

I know the way to retreive how many boxes are checked and can indentify them with this sniplet:

<%
chkCnt=request.form("checkbox").count
response.write "Number of boxes checked: "&chkCnt&"<BR>"
i=1
if chkCnt > 0 then
  do while i <=chkCnt
    response.write "Boxnumber " & request.form("checkbox")(i) & " is checked." &"<BR>"
  i=i+1
  loop
end if
%>

But how can I catch the given value in the text input?

in this script?

Thanks
LVL 1
SteynskAsked:
Who is Participating?
 
SteynskConnect With a Mentor Author Commented:
I solved my own question:

if chkCnt > 0 then
  do while i <=chkCnt
   volgnummer = request.form("checkbox")(i)
   tijd = "tijd-" & volgnummer
    response.write "volgnummer " & request.form("checkbox")(i) & " is aangevinkt met waarde " & request.form(tijd) & "<BR>"
  i=i+1
  loop
end if
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Let's say you have 8 checkbox's on your form.  Each checkbox has the same name. In your example, you named it, "checkbox".  Now lets assume each check box has a given value 1 through 8 where the first checkbox is 1...and the last is 8.  

Now you need to catch and maybe store the values of the checkex box's.  

First the checked value of the box's with the same name (or any form fields with the same name) is a comma separated list.  So if box's 1, 3 and 5 are checked and you simply looked at your submitted data via response.write request.form("checkbox") you would see, "1,3,5".

First to store this data, it is very common to simply store the data to a text field in the database.  Just make it long enough to handle all the values if checked.

Next you need to parse out the checked or saved value.  Since it is a comma separated list, we just need to turn it into an array and loop through it.

Assuming form submitted:
strCheckbox=request.form("checkbox")
arrCheckbox=split(strCheckbox,",") ' split based on the comma
'now loop through the result
For each x in arrCheckbox
  response.write x
next
' maybe you need to see if checkbox 5 is checked
for each x in arrCheckbox
     if cstr(x)="5" then
               response.write "Found a match"
    end if
next
' another option is instr

if instr(1,strCheckbox,"5",1 )> 0 then ' notice here I used strCheckbox and not arrCheckbox
               response.write "Found a match"
end if

Open in new window

I think the first way can be more accurate.
0
 
SteynskAuthor Commented:
Thanks Padas,

But the part you try to explain has been solved as you can see in the last part of the question.

I need to capture the text input part of form.
0
 
SteynskAuthor Commented:
I solved my own question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.