473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing checkbox values from one JSP page to another

10 New Member
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 6732
delram
10 New Member
Figured out.
Thanks..
May 30 '07 #2
kriti001
1 New Member
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 Recognized Expert Top Contributor
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
11084
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, need to iterate through pages page2 - e.g. allow user to update the fields there) On page1 I have a bunch of checkboxes with the same name v1 but different values (= DB rowId).
1
11862
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 (Left, Content, and Footer) In the content page, I have a checkbox, which value is a number (i.e. 500). I would like that, when a user clicks on this checkbox, it will send the value to my LEFT frame. My left frame has an array, where I'm going to...
11
4314
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=<%= iPageCurrent - 1 %for Previous. Now when i display the contents i also add a checkbox (for deletion) to each of the records. Now user should be able to select one or more checkboxes across pages and then should be allow to delete all selections together....
3
2487
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
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9332
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.