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

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();
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.