473,287 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Passing checkbox values from one JSP page to another

10
I'm trying to get user selections (using checkboxes) on one JSP page(A.jsp) and pass them on to another page.


So I have one page with a list of dynamically populated items like this

1 [checkbox]
2 [checkbox]
...
...
n [checkbox]

Submit button


So the second page(B.jsp) needs to say " You selected 1,2,3" (apart from stuffing them into a database)

Here's a snippet of code from A.jsp

Expand|Select|Wrap|Line Numbers
  1. ========================================================
  2.  <% String url = "jdbc:mysql://...";
  3. String user= "";
  4. String pass= "";
  5. String temp = "_";
  6. try{
  7.       Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  8.       Connection conn = DriverManager.getConnection(url, user, pass);
  9.       Statement stmt = conn.createStatement();
  10.       ResultSet rs = stmt.executeQuery("SELECT * FROM <tablename>");
  11.  
  12.       while(rs.next()){ %>
  13.                         <table><tr>
  14.                         <td><b><%= rs.getString("ID") %></b></td>
  15.                         <td><%= rs.getString("DESCRIPTION") %></td>
  16.                         <td> <input name="Select" type="checkbox" value="<%=rs.getString("ID")%> checked"></td>
  17.                         </tr></table>
  18.  
  19.                          <% String selection = rs.getString("ID");
  20.                         temp = temp + selection + "_"; 
  21.                          }                         
  22.                         rs.close();
  23.                         conn.close();
  24.                         }catch(Exception e)
  25.                                        {out.println(e.toString());   
  26.                                        }
  27. %>
  28. </p>
  29. <p>&nbsp; </p>
  30.     <form name="form1" method="post" action="B.jsp">
  31.       <label>
  32.       <input type="submit" name="Select" >
  33.       </label>
  34.     </form>
  35.     </BODY>
  36. ========================================================
  37.  
The table in question has 2 columns - ID and DESCRIPTION. I also need to capture the IDs from all the user selections and pass them on to page 2 as a string

If the user selects items 1, 2, 3, I need to pass _1_2_3

I'm not familiar with checkboxes and unable to capture only those that the user selects. In the example above, I'm trying to capture only those IDs from the checkboxes the user selects under temp. Right now, every single ID is appended to temp and it looks like _1_2_3_...._n.


Can you pls. take a look at the code?
Thank you for your time!

D.
May 29 '07 #1
3 6704
delram
10
Figured out.
Thanks..
May 30 '07 #2
how did u do that I have the same problem. Can u please explain me. thanks in advance.
Jun 2 '10 #3
jkmyoung
2,057 Expert 2GB
Are you using a form, and creating an input like so
<input type="checkbox" name="field1"...>
??
Jun 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox,...
1
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames...
11
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, I have a large recordset to be displayed on a ASP 3.0 page. I am using recordset paging for this. For the next and previous link i am passing href as <a href=<Page URl>?page=<%=...
3
by: Archanak | last post by:
Hi, Any limits exists while passing values of checkbox to another program? Here is the code: <script type="text/javascript"> function valuate() {
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.