Problem to display checkbox item

Problem to display checkbox item

Hi, Following is my code:

<%@page import="java.sql.*"%> 
<h1>example.jsp</h1> 
<table border="1"> 
  <tr>
  <td></td> 
  <th>domainName</th> 
</tr> 
<% 
try{ 
Connection conn = null; 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/entity","root", "rahul"); 
ResultSet rs = null; 
Statement st=null; 
st=conn.createStatement(); 
rs = st.executeQuery("select * from domain where categoryId=1"); 
while(rs.next()){ 
%> 

<tr>
<td>
    <input type="checkbox" name="check" 
    value=<%= rs.getString("domainId") %> 
    onClick="if (this.checked) {showState(this.value)()}" value="ON">
</td> 
<td><%= rs.getString("domainName") %></td> 

</tr> 

<% 
} 
}catch(SQLException e){ 
    System.out.println(e.getMessage()); 
} 
%>

<tr>
<td>
<input type=submit value="submit">
</td>
</tr>


</table>

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.

View Answers

October 20, 2010 at 4:43 PM

Hi Friend,

We have made changes in the code:

1)checkboxExample.jsp:

<%@page import="java.sql.*"%>
<head>  
 <script>  
 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);
      i--;
    }
  }
  return this;
};

 function showState(){ 

var total=""
for(var i=0; i < document.form.check.length; i++){
if(document.form.check[i].checked)
arr[i]=document.form.check[i].value;
}
arr.clean(undefined);
   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=" +arr;
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>
<form name="form">
<table border="1">
<tr><td></td>
<th>Id</th>
<th>Name</th>
<th>Address</th>
</tr>
<%
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") %> ></td>
<td><%= rs.getString("empid") %></td>
<td><%= rs.getString("name") %></td>
<td><%= rs.getString("address") %></td>
</tr><%
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="button" value="submit" onClick="showState();">
</form>
<br>
<br>
Selected Data<br>
<div id='sel'>  
</div>

October 20, 2010 at 4:44 PM

2) gettable.jsp:

<%@page language="java" import ="java.sql.*" %>  
 <%  
String val[] = request.getParameterValues("val");
String st="";
for(int i=0;i<val.length;i++){
    st+=val[i]+"";
}
    String str[]=st.split(",");
    for(int i=0;i<str.length;i++){
        System.out.println(str[i]);
    }
 ResultSet rs = null;
 String buffer="";  
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 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+"'");  
   while(rs.next()){

   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


October 20, 2010 at 6:42 PM

Thank you Deepak for your valuable reply...........:-) it really works

But,I want some 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 your 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


October 20, 2010 at 7:46 PM

Thank you Deepak for your valuable reply...........:-) it really works

But,I want some 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 your 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


October 21, 2010 at 11:46 AM

Hey please, help me.. i am new in java and jsp

please, send me modified code

waiting your reply









Related Tutorials/Questions & Answers:
Problem to display checkbox item
Problem to display checkbox item  Hi, Following is my code: <... include next page's selected checkbox in display list on same pages respectively.( i... can display all selected checkbox)ADS_TO_REPLACE_6 Please,please help me
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt....()); CheckListItem item = (CheckListItem) list.getModel().getElementAt
Advertisements
Display Problem
Display Problem  i am creating a small window application , i want to fetch data from ms-access(db) and want to display it on tables. what options are there to show result on table. is CSS helpfull
Problem with DOJO tree with checkbox - Framework
Problem with DOJO tree with checkbox  Hi Friends, I have to generate a tree structure in a jsp along with checkbox besides each node. The tree... opens with tree structure. The checkbox will have 3 states: (1) partially
Checkbox pagination problem
Checkbox pagination problem  HI ., Following is my code test.jsp... Total Selected Domains " type=checkbox... not getting it. when i click on some checkbox of table"Table Containts" and submit
nested selected tag ihave display selected item
nested selected tag ihave display selected item   i have two combo...="2">UK etc in other combo box display all states relate first combo box, ok it can be done by creating array my problem is when i display data like
iterator display problem - Struts
iterator display problem   in action class i store database data in arrraylist but after success how can i display those data in jsp page using... friend, Code to help in solving the problem : Iterator Tag
Checkbox Problem--Please Check this - JSP-Servlet
Checkbox Problem  I am facing a problem while creating a check box in JavaScript. Can any one share the part of code to create a checkbox in JavaScript
Jfreechart chart display problem
Jfreechart chart display problem  Using JSP and Jfreechart displays the chart fine on an internal browser in eclipse but doesnt display it on Chrome...(request.getParameter("q")); String query="select dateof,dayinprice,company from stockprice
Integer display problem
Integer display problem  class Bean{ int n1,n2; public Bean(){ } public Bean(int n1, int n2){ this.n1=n1; this.n2=n2; } public...); } } In above program value of n1 should display 10. But it is displaying 8. what
Problem with display of images in applets - Applet
Problem with display of images in applets  Hi all, When I run... in figuring out the problem....  Hi frined, import java.applet.*; import..., this); } } --------------------------------------- Display image in Java Applet
select Query result display problem
select Query result display problem  Hi, String SQL_QUERY ="from Cc"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Object[] row = (Object[]) it.next
JComboBox Display Problem - Java Beginners
JComboBox Display Problem  I am create one program that contain two combo boxes. If first combo box i am display all date. If i select one date from first combo box then the second combo box display some dates based on first
Display values in textbox on selecting checkbox
Display values in textbox on selecting checkbox Here we are going to perform action on selecting the checkbox and display the first five text box values into next five. We have ten text boxes and a checkbox. As the user enters value
Display JSP selected listbox and checkbox in xml-please help me
Display JSP selected listbox and checkbox in xml-please help me  Hi... as well as checkbox list from database. and in final page it should display all... jsp. When user select something from 2nd list, third page contains checkbox
display records with images problem - JSP-Servlet
display records with images problem  hello, i am developing HR application whereby i want to display employee records and their pictures on web... with a unique id. Also i wrote i jsp that link to servlet in order to display
checkbox
checkbox  how to insert multiple values in database by using checkbox in jsp
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.  The code for retrieving data from database into Drop Down List. <% DataSource data = new
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
Dojo Tree With Checkbox - Framework
structure in a jsp along with checkbox besides each node. The tree structure... with tree structure. The checkbox will have 3 states: (1) partially checked, (2.... and after selecting the values I've to display those values in the parent page
item lookup
item lookup  I need to create a lookup box in a grid that searches and filters at the same time. Upon selection the item with its price should be displayed. The control would then position below the first selection, so
Item renderer in flex
Item renderer in flex  Hi..... I have a problem How do you call a method in particular ItemRenderer. Also the ItemRenderer is your own Custom Component? please give me an example for that...... Thanks
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
Item renderer in flex
Item renderer in flex  Hi..... How does item renderer work? How do I add item renderer at runtime? Please me the right answer so i cam implement this in my apps. Thanks  Ans: The base class for Spark item
Maintain checked checkbox status
Maintain checked checkbox status  Hi everyone In my JSP application, i have database table stored in mysql. when i display there recors using... display that "selected checked checkboxes" in same page but in another table
Checkbox method
Checkbox method  what is the method to check if the checkbox is checked
JSP CheckBox
JSP CheckBox          JSP CheckBox is used to create a CheckBox in JSP... checkbox and also print the userdefined message that specify the languages option
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
return item in jquery
return item in jquery  How to return items/variables in JQuery?   See the code below to find out how to return an Item in Jquery: function findItem() { var item; while(if_item_not_found) { // search
delete an item from database
delete an item from database  how to delete an item from the database using jsp
ModuleNotFoundError: No module named 'item'
ModuleNotFoundError: No module named 'item'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'item' How to remove the ModuleNotFoundError: No module named 'item' error
Checkbox blocked - WebSevices
Checkbox blocked  Hi, i design online ticket reservation for bus. It contains no of seats. if i choose 3 or 4 seats checkbox,it will stored in my database. After i refreshing the page that checkbox seats are blocked
UIButton checkbox
UIButton checkbox  iPhone UIButton checkbox example required.. can any one please explain me.. how to create a checkbox button using UIButton in XIB
Item renderer in flex
Item renderer in flex  Hi...... please tell me about How to create item renderers in flex? give an example for that Thanks
Checkbox
Checkbox       A checkbox is again a label which is displayed as a pushbutton as shown in the example... of the checkbox is either true or false. However, the initial state is false
navigation item back button
navigation item back button  I wants to add a navigationBar on the top of my UIWebView also a navigation item "back button". can anyone please explain how the back and refresh button works
Ajax Checkbox
Ajax Checkbox  I want ajax code for checkboxes.The scenario is that if a selectbox is selected the corresponding values to it in the database table are to be checked in the checkbox.....Please do help me
print selected checkbox names in array without form tag
print selected checkbox names in array without form tag  Hi everyone ... I have problem in my program. I have hashmap i.e. collection , my...;% %> [/code] so, i want to display all
Item renderer in flex
Item renderer in flex  Hi... Please tell me about what does listData contain in ItemRenderers? What is the Type of listData? please give an example for that........ Thanks
highlight menu item html
highlight menu item html  highlight menu item in html or CSS   <body id="index"> <div id="menu"> <ul> <li class="index" ><a href="index.html">Index page</a></li> <
refresh checkbox jframe
refresh checkbox jframe  How to refresh checkbox button in JFrame
enable disable checkbox in javascript
enable disable checkbox in javascript  How to enable disable checkbox in javascript
Reset checkbox style to default
Reset checkbox style to default  Reset checkbox style to default   input[type="checkbox"] { /* styles
Linking JMenu Item with a JPane in Netbeans
Linking JMenu Item with a JPane in Netbeans  How do you link a Jpane window to a JMenu Item in Java Netbeans
CheckBox in Flex
a particular CheckBox item. <mx:CheckBox> tag is use to access...Flex CheckBox Control: The CheckBox control of Flex is a very common GUI, which is supported by almost every computer language. CheckBox control is used when
JavaScript Checkbox getElementById
JavaScript Checkbox getElementById...() for checkbox in JavaScript. In the given example we are going to show an image on clicking the checkbox. This is done by using the JavaScript method getElementById
Display Tag
Display Tag  Hi Here is My code, There is problem At line no.3, where i want to display two fields in one column but it gives error.. Please any one knows the solution must reply Thanks In Advance
Display Tag
Display Tag  Hi Here is My code, There is problem At line no.3, where i want to display two fields in one column but it gives error.. Please any one knows the solution must reply Thanks In Advance
ModuleNotFoundError: No module named 'item-tracking'
ModuleNotFoundError: No module named 'item-tracking'  Hi, My... 'item-tracking' How to remove the ModuleNotFoundError: No module named 'item-tracking' error? Thanks   Hi, In your python

Ads