473,414 Members | 1,946 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,414 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 6715
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.