Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Form with Multiple Checkbox $ ASP

Posted on 1998-07-19
8
Medium Priority
?
203 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 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