how to display checked ckeckbox in same jsp page?
Hi,
Here is the html code to display check box:
<html> <head> <title>Test Page</title> </head> <body> <form method="post"> <p>Check box:<input name="Checkbox1" type="checkbox"> </p> </form> </body> </html>
Please let's know if you any other query.
Thanks
Thanks deepak for your reply. But I havw database store in server. From that database, i have displayed all values with checkbox in one table.
Now i want to display ,selected checked checkboxes in another table in same jsp page.
(for example, as it happens in VB that after clicking checkbox and submitting it goes to another table ...dynamically)
All it shoud happen dynamically.
Please help me.
Hi,
You may use the jqgrid
Please check the demo at jqgrid website.
You can use its Subgrid module. This module will allow you to crate grid and subgrids.
See it at http://www.trirand.com/blog/?page_id=6
Regards Deepak Kumar
Thanks deepak for your reply.
But, instead of using other grid modules, can it be possible with help of java code or jsp or html ....
Please help me.
Hi Friend,
Try the following code:
checkboxExample.jsp:
<%@page import="java.sql.*"%> <head> <script> var xmlHttp function showState(id){ 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") return } var url= "gettable.jsp"; url += "?val=" +id; xmlHttp.onreadystatechange = stateChange; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function stateChange(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("sel").innerHTML=xmlHttp.responseText; } } </script> </head> <table border="1"> <tr><td></td> <th>Id</th> <th>Name</th> <th>Address</th> </tr> <% int i=0; 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(rs.next()){ %> <tr><td><input type="checkbox" name="check" value=<%= rs.getString("empid") %> onClick="if (this.checked) {showState(this.value)()}" value="ON"></td> <td><%= rs.getString("empid") %></td> <td><%= rs.getString("name") %></td> <td><%= rs.getString("address") %></td> </tr><% i++; } }catch(SQLException e){ System.out.println(e.getMessage()); } %> </table> <br> <br> Selected Data<br> <div id='sel'> </div>
continue..
gettable.jsp:
<%@page language="java" import ="java.sql.*" %> <% String val = request.getParameter("val").toString(); int id=Integer.parseInt(val); String buffer=""; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT * FROM employee WHERE empid='"+id+"'"); while(rs.next()){ String name=rs.getString(2); buffer=buffer+"<table border><tr><td>"+rs.getString("empid")+"</td><td>"+rs.getString("name")+"</td><td>"+rs.getString("address")+"</td></tr></table>"; } response.getWriter().println(buffer); %>
Thanks
Deepak,....Thanks for your valuable reply
your code works properly. But when i made some changes according to my need, i am getting problem.
I am sending you .jsp file
<%@page import="java.sql.*"%>
domainName | |
---|---|
onClick="if (this.checked) {showState(this.value)()}" value="ON"> | <%= rs.getString("domainName") %> |
I want to display records, when i click on submit button or any dumy button like submit.
for your info. In above code, it contains,
"domain" table containg three columns.
domainId--as number domainName--as string categoryId--as number
Plese, help me.
Deepak,....Thanks for your valuable reply
your code works properly. But when i made some changes according to my need, i am getting problem.
I am sending you .jsp file
<%@page import="java.sql.*"%>
domainName | |
---|---|
onClick="if (this.checked) {showState(this.value)()}" value="ON"> | <%= rs.getString("domainName") %> |
I want to display records, when i click on submit button or any dumy button like submit.
for your info. In above code, it contains,
"domain" table containg three columns.
domainId--as number domainName--as string categoryId--as number
Plese, help me.
Thank you for your valuable reply, but i code which you have sent above...
i want select multiple checkbox at a time and on click of button it should disply all selected checkbox details.....
please, how to modify in above code.. please, help me.I am new to jsp & java
Hey please, help me.. i am new in java and jsp
please, send me modified code
waiting your reply
Ads