Home Answers Viewqa JSP-Servlet want to ask how to update data for runtime selected multiple checkboxes

 
 


archana pande
want to ask how to update data for runtime selected multiple checkboxes
1 Answer(s)      4 months and 25 days ago
Posted in : JSP-Servlet

HI I have one problem I have fetched value from oracle database into grid and created runtime textboxes in the grid for the column geocoordsN,GeocoordsE I have checkboxes for each record when I will select more than one checkboxex and entered the values in the textbox then it should get update in the database.I have succesfully updated when I am clickinga single checkbox but I want to update for more than One checkbox here is my code.

<%@ page language="java" import="java.sql.*;" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="javascript">
var rowNumber;
function check23(abc)
{
/*     alert(document.getElementById("textbox1").value);
    document.getElementById("textbox1").value= abc;
    alert(document.getElementById("textbox1").value);
    document.getElementById("textbox2").value=document.getElementById("textbox1").value; */
}

function getSelected(row)
{
    rowNumber = row;
    alert(rowNumber);

}
function getVal()
{
    alert(rowNumber);
    document.getElementById("coords1").value = document.getElementById("coordsN"+rowNumber).value;
    document.getElementById("coords2").value = document.getElementById("coordsE"+rowNumber).value;
    alert( document.getElementById("coords1").value);
    alert( document.getElementById("coords2").value);
}

function selectCheckBox()
{
    alert('hi');

  var e= f1.elements.length;

 alert(e);
  var cnt=0;

var j=0;



var name=new Array();
var values=new Array();
alert("array declared");
  for(cnt=0;cnt<e;cnt++)
  {
    if(f1.elements[cnt].name=="test"){
     alert(f1.elements[cnt].value);
//alert("enter");  
if(f1.elements[cnt].checked==true){
    values[j]=f1.elements[cnt].value;
    alert('getting....:'+cnt+': e: '+e);
    alert("gggg="+values[j]);
    j++;


  }

    }


  }

}


</script>
</head>
<body text="Red" bgcolor="#CC99FF">
<h1>SARDA FARMS DISTRIBUTION</h1>
<HR></HR>
<H2>ROUTE ASSIGNMENTS TO NON-ROUTES CUSTOMERS</H2>
<H3>LIST OF CUSTOMERS-ADDRESS TO BE CONFIRMED</H3>

<input type='hidden' name ='hh' value="<%=request.getParameter("textbox1") %>" >






</body>
</html>
<%  Connection conn=null;
Statement ps=null;

String stdate1,enddate1;

try
{


 String r="";
 String option1;
 String driver = "oracle.jdbc.driver.OracleDriver";
 String url = "jdbc:oracle:thin:@10.0.0.7:1521:CRM";
 String username = "SFCRM";
 String password = "SFCRM";

  Class.forName(driver);
  conn = DriverManager.getConnection(url, username, password);
  String qry="select Profile_Id,Profile_Name,Address_Line1,Address_Line2,Landmark,Geo_Coords_N,Geo_Coords_E from CRM_PROFILE";
  ps = conn.createStatement();
 ResultSet  rs=ps.executeQuery(qry);
 out.println("<html><body>");
 out.println("<form action='transfer.jsp' id='f1'  method='post' >");
 out.println("<table Id=dataTable border=1  bordercolor=#8080cc bordercolorlight=#8080c0 bordercolordark=#400080 bgcolor='#CCFFFF'>");
 out.println("<tr><th>select</th><th>Profile_Id</th><th>Profile_Name</th><th>Address_Line1</th><th>Addres_Line2</th><th>Landmark</th><th>Geo_Coords_N</th><th>Geo_Coords_E</th><tr>");
 System.out.println("enter");
 int i=1;
 while(rs.next())
  { 
  r=rs.getString(1);
  String pname=rs.getString(2);
  String add1=rs.getString(3);
  String add2=rs.getString(4);
  String land=rs.getString(5);

               //out.println("<tr><td>"+"<input type='checkbox' id='r1' value="+r+" name='test'>"+"</td><td>"+r+"</td><td>"+pname+"</td><td>"+add1+"</td><td>"+add2+"</td><td>"+land+"</td>");
               //out.println("<tr><td>"+"<input type='checkbox' id='r1' value="+r+" name='test' onclick='check23(this.value);'>"+"</td><td>"+r+"</td><td>"+pname+"</td><td>"+add1+"</td><td>"+add2+"</td><td>"+land+"</td>");
               //out.println("<tr><td>"+"<input type='checkbox' id='r1' value="+r+" name='test' onclick='getSelected("+i+")'>"+"</td><td>"+r+"</td><td>"+pname+"</td><td>"+add1+"</td><td>"+add2+"</td><td>"+land+"</td>");
  out.println("<tr><td>"+"<input type='checkbox' id='r1' value="+r+" name='test' onclick='getSelected("+i+");selectCheckBox();'>"+"</td><td>"+r+"</td><td>"+pname+"</td><td>"+add1+"</td><td>"+add2+"</td><td>"+land+"</td>");

               /* out.println("<td><input type = 'text' name='coords1' id='coords1'></td>"); */
               /* out.println("<td><input type = 'text' name='coords2' id='coords2"+i+"'></td>"); */

 out.println("<td><input type = 'text' name='coordsN' id='coordsN"+i+"'></td>");
 out.println("<td><input type = 'text' name='coordsE' id='coordsE"+i+"'></td>");

 out.println("<td><input type = 'hidden' name='coords1' id='coords1'></td>");
 out.println("<td><input type = 'hidden' name='coords2' id='coords2'></td>");
               //out.println("<td><input type = 'checkbox' name='check' id='check"+j+"' onclick='checknum("+j+")'></td>");

 out.println("</tr>");
 i++;

 }
 out.println("<tr><td><input type='submit' id=b1 value='submit' onclick='getVal();selectCheckBox();'></input></td></tr>");
          // out.println("<input type='text' id='textbox1' name ='textbox1'/>");

 out.println("</table>");
 out.println("</form>");
}
catch (Exception e) {
out.println("error");
}
           %>
View Answers

January 25, 2013 at 7:20 PM


hi, friend you can add an input hidden field that should return the row numbers as follows :

out.println("<td><input type = 'hidden' name='row' id='row' value="+i+"></td>");

try this snippet code in transfer.jsp page this may helpful for you.

<%@ page language="java" import="java.sql.*;"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>

</body>
</html>
<%
Connection conn=null;
PreparedStatement ps=null;
String coords1[] = request.getParameterValues("coordsN");
String coords2[] = request.getParameterValues("coordsE");
String rw[] = request.getParameterValues("row");
int row=0;
int i=0;
try
{
//String r ="";
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/record";
String username = "root";
String password = "root";

Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
String qry="update crm_profile set Geo_Coords_N=?,Geo_Coords_E=? where Profile_Id=?";
String query = "select Profile_Id from crm_profile";
ps= conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
String id = (String)(rs.getString("Profile_Id"));
int pid = Integer.parseInt(id);
System.out.println(pid);
for(int r=0; r<rw.length; r++)
{
row = Integer.parseInt(rw[r]);
if(row == pid)
{
ps = conn.prepareStatement(qry);
ps.setString(1,coords1[r]);
ps.setString(2,coords2[r]);
ps.setInt(3,row);
i = ps.executeUpdate();
}
}
}

if(i>0)
{
out.println("value updated successfully");
}
}
catch (Exception e) {
e.printStackTrace();
}
%>









Related Pages:
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes ... have succesfully updated when I am clickinga single checkbox but I want to update... and created runtime textboxes in the grid for the column geocoordsN,GeocoordsE I
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected multiple checkboxes   suppose this if form1.jsp in which i am going... values which is selected from form1.jsp String languages=""; String box
Updating multiple value depending on checkboxes
Updating multiple value depending on checkboxes  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
Retriving multiple values of checkboxes in struts
Retriving multiple values of checkboxes in struts  how to retrive multiple values of checkboxes of jsp in action class   JSP Retrieve... selected:"); for(int i=0;i<st.length;i++){ out.println(st[i
I want to update the multiple values of database depending on checkbox..? Please help me out..
I want to update the multiple values of database depending on checkbox..? Please help me out..   Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes
how to get data from checkboxes - JSP-Servlet
how to get data from checkboxes  hi, i got list of tables on screen by invoking webservices.when the user selects the tables by using checkboxes, i... to that selected tables. please help me.  hi, we can get the selected
how to display selected checkboxes dynamically using jsp
how to display selected checkboxes dynamically using jsp  Hi friends i have a requirement that : in my JSP page i have radio buttons...) is available in DB,the respective radio button should be selected automatically
Array of checkboxes - Struts
Array of checkboxes  How to handle unknown number of checkboxes using tag in an ActionForm.   Hi friend, Code for multiple checkbox...;%-- html code, etc... --> <%-- create the checkbox and selected
How to insert multiple checkboxes into Msaccess database J2EE using prepared statement - Java Beginners
How to insert multiple checkboxes into Msaccess database J2EE using prepared... statement to do the checked boxes part, I'm not sure how to go about doing... with the form data ps.setString(1, strID
data update
the entire data which is retreived .After editing the data i want to save... edit/update data and saved them into that table again...data update  sir, I have a table consist of huge data.I have
update the selected records from view immediatly
update the selected records from view immediatly  Hi I am extracting data form sql view to Excel(2007). I want update the Flag field (CHAR 1)in one... update the records immedialty in view as soon as see the data form view. Thank
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well as in store that unchecked checkboxes in ARRAYLIST
checkboxes,after checking some of checkboxes, i want to delete selected (checked... in ARRAYLIST. I want to delete checked checkboxes.And store all unchecked checkboxes...Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well
Maintaining States of Selected CheckBoxes in Different Pages using dispaly table in struts2
the checkboxes selected across different pages will get submitted. Can somebody help me how to maintain States of Selected CheckBoxes in Different Pages using...Maintaining States of Selected CheckBoxes in Different Pages using dispaly
Ask about looping in database
=True,A2=True : code is the same data Rule and Heritage. I want to ask that how to read looping in field rights(if A1=false and A2 = True), use from java. i...Ask about looping in database  Good afternoon, I want to ask
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit the entire data which is retreived .After editing the data i want to save
The UPDATE Statement
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through... in a Row: If we want to change the multiple values of a table like in employee
update database
update database  hi.. i want to know how the valuesof database can be updated in the jsf-jpa framework when the drop down button is clicked the data will be displayed in the data table and if some changes has to be made
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam getting all column names of a particular table with checkboxes. when iam select one or more checkboxes i have to get data of that selected columns only. what
Display JSP selected listbox and checkbox in xml-please help me
as selected multiple checked checkboxes. Please help in this how to do this.....I am...Display JSP selected listbox and checkbox in xml-please help me  Hi, I have three Listbox on my jsp page. I want to do following: ByDefault first
The UPDATE Statement, SQL Tutorial
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through... in a Row: If we want to change the multiple values of a table like in employee
ask java - Date Calendar
ask java  sory i'am wrong language. i want to ask to this forum how... but in java i found too but i can't to join in another frame. And i want to ask how... day right, how to get 1 month 10 day?.need help please give me a way and tutorial
Data from multiple ResultSets?
Data from multiple ResultSets?  hello, How can I get data from multiple ResultSets?   Hi, You can iterate the ResultSet separately and get the required data. Thanks
How to send the data selected from drop down menu from html page to sql 2005 database.
How to send the data selected from drop down menu from html page to sql 2005 database.  Dear Sir, If I want to save the information provided... system ,how can I save these data in database and how to retrieve later .Thanks
How to ask a questions to you clearly with normal english?
How to ask a questions to you clearly with normal english?  hi, i want to know how should or can i may ask a question. send me some format... in the same way as you have asked this question. Go to the Ask Questions part
update multiple rows in jsp - JSP-Servlet
update multiple rows in jsp  Hi I am trying to do a multiple row update in JSP. code as follows.. > Can you please tell me how to get this form values in actio page  Hi Friend
ask how function jCalender - Date Calendar
ask how function jCalender  d, Halo friend, i want to ask how to make this script can run and call JCalender. I want to know how to make private this code.i has already insert plugin in my netbeans. try
JavaScript Array of checkboxes
JavaScript Array of checkboxes       In this Tutorial we want to describe you a code that help you in understanding JavaScript Array of checkboxes. For this we
Insertion of multiple row data for billing purpose.
Insertion of multiple row data for billing purpose.  Hi , I have...)========(inutfield2) I want to insert all these row value .problem is that the no of text field in row/column can be dynamic. so how can i insert all
JSP Servlet update patient data - JSP-Servlet
_update="Data has been successfully inserted!"; String title="Update Message...JSP Servlet update patient data  Hi Friend, I'm attaching my inserting patient data servlet as requested. I tried your posted code, its
Second tab should only show selected products from first tab
Second tab should only show selected products from first tab  In the javascript, From the comment ââ?¬Â? // live update of how many circlesââ?¬Â...("width","150px"); $('.tabs').tabs(); // live update of how many circles
Update / Edit data
Update / Edit data  Hello, i want to create a page to edit or update... number, i want the data for that reference no to automatically appear in the form..., that data will get shown in another page and allow the user to update
fill combobox at runtime jsp
another combobox below it, i want it to be filled on the basis of selected value...fill combobox at runtime jsp  i have 1 combobox in jsp which is filled with value from sql db on load of form <% Class.forName
how to retrieve data from table with runtime values in sql?
how to retrieve data from table with runtime values in sql?  how to retrieve data from table with runtime values in sql? For example, I have table... to execute the command with the dates which I pass. I know how to retrieve a particular
dropdown wth checkboxes - Design concepts & design patterns
want to put checkboxes inside the dropdown,then we can check the options whatever we want. Please give me the html code(only html & javascript). Thanks..." } if(total=="") alert("select scripts") else alert("Selected Values
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...;" <?php if($row_list['Age_Id']==$select){ echo "selected"; } ?>> <
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...;" <?php if($row_list['Age_Id']==$select){ echo "selected"; } ?>> <
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...;" <?php if($row_list['Age_Id']==$select){ echo "selected"; } ?>> <
Display Label and radio buttons runtime with respect to DB values
can we get selected values of radiobuttons at runtime and updated back to DB...Display Label and radio buttons runtime with respect to DB values  ... from buttongroup-Y JradioButton from buttongroup-N and i have multiple values
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i... query acording to the checkbox. whichever checkbox is selected query should
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i... query acording to the checkbox. whichever checkbox is selected query should
How to execute mysql query based on checkboxes values in java swing application.
How to execute mysql query based on checkboxes values in java swing application.  Hello Sir, I have a java swing application and i... query acording to the checkbox. whichever checkbox is selected query should
Not able to display jtable at runtime
Not able to display jtable at runtime  Hello, can anyone please help me. I am trying to create a dynamic table with checkboxes. Data are accessed from database. But it is not creating the table at runtime. It retrieves data from
how to use update - Java Beginners
how to use update  Hi all, your all code is perfect thanks. I... taken from database but view modify and delete is link if user click modify data then only open the popup windows with dynamic data...this pop-uphave 1 modify