Solved

Form with Multiple Checkbox $ ASP

Posted on 1998-07-19
8
190 Views
Last Modified: 2013-12-25
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
Comment
Question by:sangeli
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:sangeli
ID: 1858602
Edited text of question
0
 
LVL 28

Accepted Solution

by:
sybe earned 100 total points
ID: 1858603
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
 
LVL 7

Expert Comment

by:BlackMan
ID: 1858604
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
 

Author Comment

by:sangeli
ID: 1858605
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:sangeli
ID: 1858606
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
 
LVL 7

Expert Comment

by:BlackMan
ID: 1858607
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
 
LVL 28

Expert Comment

by:sybe
ID: 1858608
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
 
LVL 7

Expert Comment

by:BlackMan
ID: 1858609
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now