Solved

Form with Multiple Checkbox $ ASP

Posted on 1998-07-19
8
200 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 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

729 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