want to ask how to update data for runtime selected multiple checkboxes

Ads
 

want to ask how to update data for runtime selected multiple checkboxes

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();
}
%>

Ads









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
ModuleNotFoundError: No module named 'ask-sdk-model-runtime'
: No module named 'ask-sdk-model-runtime' How to remove the ModuleNotFoundError: No module named 'ask-sdk-model-runtime' error? Thanks   Hi...ModuleNotFoundError: No module named 'ask-sdk-model-runtime'  Hi
ModuleNotFoundError: No module named 'ask-sdk-model-runtime'
: No module named 'ask-sdk-model-runtime' How to remove the ModuleNotFoundError: No module named 'ask-sdk-model-runtime' error? Thanks   Hi...ModuleNotFoundError: No module named 'ask-sdk-model-runtime'  Hi
ModuleNotFoundError: No module named 'ask-sdk-runtime'
named 'ask-sdk-runtime' How to remove the ModuleNotFoundError: No module named 'ask-sdk-runtime' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'ask-sdk-runtime'  Hi, My
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
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
Delete multiple records with pagination by selecting checkboxes
Delete multiple records with pagination by selecting checkboxes  Hi there,I'm working with PHP.I want to delete my database records which... each page wise.I want to check all the desired records from all the pages
how to display the selected row from the data table in model panel ??
how to display the selected row from the data table in model panel ??  the below displayed is my datatable:tableDatas.xhtml <rich...(rec3); } public ArrayList <TableData> selected() { Iterator<
i want to update values
i want to update values  in my form i have 2 submit buttons one for edit and another for update on page load all my details need to fetch from... and later once i press update it need to update details into database and before
how to update
how to update   conditional update
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
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
ordering the data on a selected key
ordering the data on a selected key  I am willing to present the data in a particular event order
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
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc  how to make a radio button selected when retrieving data from database using struts framework and spring jdbc
How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?
How to obtain the selected data item from a list box when listbox contains... page. The listbox gets populated by the data contained in the arraylist. Now, I want to copy the selected item(one at a time) from the list box to the text box. I
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
JPA update data Example
JPA update data Example       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. To update the data
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

Ads