?
Solved

Form with Multiple Checkbox $ ASP

Posted on 1998-07-19
8
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

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

Accepted Solution

by:
sybe earned 200 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
Stressed Out?

Watch some penguins on the livecam!

 

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
 

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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

764 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