• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Form with Multiple Checkbox $ ASP

Hi,
I am trying to understand how to do the following:
1) Present a from retreaving from a database (via ODBC) a list of items to which I do assign a checkbox
2) Then the user will check on the checkbox as many as he/sch wants and click on the Submit button
3) Now what I need is to present the next web page with only the selections the user has done (only the items the
    user has checked on the checkbox)
How do I do so Using only ASP?

Thank you
Spiro
0
sangeli
Asked:
sangeli
  • 3
  • 3
  • 2
1 Solution
 
sangeliAuthor Commented:
Edited text of question
0
 
sybeCommented:
Basically it's done like this:

1. Make a recordset with all the items you want from the database and loop through it:


<form action="nextpage.asp" method="POST">
<%
Do While Not RS.EOF
%>
<input type="checkbox" name="checkbox1" value="RS("field1")>
<%
RS.MoveNext
Loop
RS.Close
%>
<input type="submit">
</form>


3.

<%
For each value in Request.Form("checkbox1")
  Response.write value & "<br>"
Next
%>


0
 
BlackManCommented:
sybe answer won't quite do..
You will have to create checkboxes with different names. Here's a cut from one of my forms, which generate the list (note, the number of fields are stored in a hidden field):

Dim Cnt
rs.Source = "Select * from Users U, Locations L, Functions F " &
                "Where F.ID = U.Jobfunction_ID And L.ID = U.Location_ID And U.Create_Date is null Order by Init"
rs.Open
Cnt = 0
Do While not rs.EOF
      If Cnt = 0 Then
%>
             <TH></TH>
             <TH Align=Center>Init</TH>
             <TH Align=Left>Navn</TH>
             <TH Align=Left>Region</TH>
             <TH Align=Left>Funktion</TH>
             <TH Align=Left>Start pr.</TH>
<%
      End If

      Cnt = Cnt + 1
%>
      <TR>
      <TD Width="10">
            <INPUT Type="Checkbox" Name="<%="CHECK" & CStr(Cnt)%>" Value="<%=rs("Init")%>">
      </TD>
      <TD Width="80">
            <A HREF="UserProp.asp?init=<%=rs("Init")%>"> <%=rs("Init")%>
      </TD>
      <TD Width="250">
            <%=rs("Name")%>
      </TD>
      <TD Width="100">
            <%=rs("Location_Name")%>
      </TD>
      <TD Width="200">
            <%=rs("Function_Name")%>
      </TD>
      <TD Width="100">
            <%=rs("Start_Date")%>
      </TD>
      </TR>
<%
      rs.MoveNext
Loop
%>
</TABLE>
<INPUT Type="Hidden" Name="NbInit" Value="<%=Cnt%>">


Now, to check which items are selected, use something like:

      For Cnt = 1 To NbInit
            Field = "CHECK" & CStr(Cnt)
            If Request.Form(Field) > "" Then
                  <do something>
            End If
      Next

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sangeliAuthor Commented:
Hi,

Thank you for your revision of the code.
I do have a question/problem:

Now that I know how to present the first page (extract data from the database and assign a checkbox with a unique name to each record) I need to do the following which is the most difficult part for me:

- let's say your code generates 10 checkbox;
- now you select 5 of them;
- then you click on submit;
- A NEW PAGE SHOUDL BE GENERATED AND SHOULD PRESENT ONLY THOSE 5 SELECTIONS WITH THE SAME NAME ASSIGNED TO THE CHECKBOX.
       How do you do so?

thank you
Spiro
0
 
sangeliAuthor Commented:
Hi,

Thank you for your revision of the code.
I do have a question/problem:

Now that I know how to present the first page (extract data from the database and assign a checkbox with a unique name to each record) I need to do the following which is the most difficult part for me:

- let's say your code generates 10 checkbox;
- now you select 5 of them;
- then you click on submit;
- A NEW PAGE SHOUDL BE GENERATED AND SHOULD PRESENT ONLY THOSE 5 SELECTIONS WITH THE SAME NAME ASSIGNED TO THE CHECKBOX.
       How do you do so?

thank you
Spiro
0
 
BlackManCommented:
That's the code in the bottom of my post, the FOR loop. Just use that in the new form, and just generate code for the checked elements.

PS. If you want more of my help, could you please reopen the question?
0
 
sybeCommented:
Blackman,
I don't see why my answer does not work, I use code like that, and it works perfectly.

There is no reason to use a different name for each checkbox, because all checkboxes with the same name which are checked will send and it can be parsed with the code I wrote.

Check it out !

0
 
BlackManCommented:
I stand corrected!!! Sorry, sybe, it works like a charm! I had this problem a year ago and I didn't find any other solution than the one I described above, properly because, as a old programmer, I'm not used to have more equal named fields...
sangeli, forget my postings and go for sybe's...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now