Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in displaying selected checked checkbox in next page  RSS feed

Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<%@page import="java.sql.*"%>
var xmlHttp;
var arr= new Array() ;
Array.prototype.clean = function(deleteValue) {
for (var i = 0; i < this.length; i++) {
if (this[i] == deleteValue) {
this.splice(i, 1);
return this;

function showState(){

var total=""
for(var i=0; i < document.form.check.length; i++){
if(typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
var url= "gettable.jsp";
url += "?val=" +arr;
xmlHttp.onreadystatechange = stateChange;"GET", url, true);
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
<form name="form">
<% try{ Connection conn = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root"); ResultSet rs = null; Statement st=null; st=conn.createStatement(); rs = st.executeQuery("select * from employee"); while({ %> <% } }catch(SQLException e){ System.out.println(e.getMessage()); } %>
Id Name Address
<input type="checkbox" name="check" value=<%= rs.getString("empid") %> > <%= rs.getString("empid") %> <%= rs.getString("name") %> <%= rs.getString("address") %>

<input type="button" value="submit" onClick="showState();">

Selected Data

<div id='sel'>

2) gettable.jsp:

<%@page language="java" import ="java.sql.*" %>
String val[] = request.getParameterValues("val");
String st="";
for(int i=0;i<val.length;i++){
String str[]=st.split(",");
for(int i=0;i<str.length;i++){
ResultSet rs = null;
String buffer="";
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt = con.createStatement();
for(int i=0;i<str.length;i++){
String ide=str[i];
int id=Integer.parseInt(ide);
rs = stmt.executeQuery( "SELECT * FROM employee WHERE empid='"+id+"'");

buffer=buffer+"<table border><tr><td>"+rs.getString("empid")+"</td><td>"+rs.getString("name")+"</td><td>"+rs.getString("address")+"</td></tr></table>";


But,I want more help from you.

In my program , i have given to link to different jsp pages. Suppose it contains two links with two different jsp pages.

Both jsp pages contains differents database tables, n it contains same checkboxes.

So, from above code, i can display selected checkbox on same page. It works...

But when i go to another page link containing same format, it does not display previous page's selected checkboxes.

So, i want such output, which can show previous pages selected checkbox as well as i aslo include next page's selected checkbox in display list on same pages respectively.( i don't know exactly, but can we store it in session and in collection so that we can display all selected checkbox)

Please,please help me... waiting for your reply
Author and ninkuma
Posts: 66425
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!