I have an HTML form (form #1) which uses a java servlet to save customer data by entering values into textfield/checkboxes/drop down fields to a mysql database(this is working fine). On the same page i also have a search facility that will search and show the results of a customer search in a small table on the same page using another servlet(also working fine). Once this dynamic table populates with results, I have an onclick function that will highlight the row(s) that the user will select(also working fine). Now my purpose is to re-populate the same customer form (form #1) based on the user selected row (either on the same page or different, doesn't matter)--this part I need Help.
Meaning, I am giving option to the user to click once on one of the rows of the search result table to select it and to edit that particular customer(s)'s data, they will double click which will trigger another (form #2 that will send this particular highlighted row's (customer id) to be matched in the database) after which I want to re-populate the form so that if the user wants to edit their data and re-save they can do so.
I've tried using a hidden field that will save this ID and pass it on to the servlet and populate the data from a stringquery into another page and having the same form, for some reason its not working. I don't know if this is the best method, I don't want to use beans. Perhaps you guys are better aware of in-place html form editing than me, because i've scoured the net fruitlessly.
May 4, 2010 at 12:20 PM
Hi Friend,
try the following code:
1)table.jsp:
<%@page import="java.sql.*"%>
<style>
.c1 {background-color: white;}
.c2 {background-color: white;}
.c3 {background-color: red;}
</style>
<script>
function ov(i){
document.getElementById(i).className="c3";
}
function ot(i,c){
document.getElementById(i).className=c;
}
function click(num){
alert(num);
window.open('
http://localhost:8080/examples/jsp/popup.jsp?id='+num,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
</script>
</head>
<form>
Search:<input type="text" name="customer"><input type=submit value="Search">
</form>
<%String name=request.getParameter("customer");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root","root";);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from client where name='"+name+"'");
%>
<table id="table" border="1">
<%
while(rs.next()){
%>
<tr id=<%=rs.getString("id")%> class=c1 onclick='click(<%=rs.getString("id")%>)' onmouseover='ov("<%=rs.getString("id")%>")' onmouseout='ot("<%=rs.getString("id")%>","c1")'><td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td><td><%=rs.getString("contactNo")%></td></tr>
<%
}%>
</table>
</html>
2)popup.jsp:
<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"'";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<form action="edit.jsp">
<table border="1">
<%
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contactNo" value="<%=rs.getString("contactNo")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString("id")%>"></td>
</tr>
<%
}
%>
</table>
<input type="submit" value="Edit">
</form>
3)edit.jsp:
<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"'";
Statement st = con.createStatement();
String name=request.getParameter("name");
String address=request.getParameter("address");
String contactNo=request.getParameter("contactNo");
int i=st.executeUpdate("update client set name='"+name+"',address='"+address+"',contactNo='"+contactNo+"' where id='"+id+"'");
out.println("Data is updated successfully");
%>
Thanks
Related Tutorials/Questions & Answers:
JSP:HTML Form in-place Editing - JSP-Servlet developer's needs.
This is a follow up to the
HTML Form in-
place editing. The code...JSP:
HTML Form in-
place Editing Hi,
I want to thank the people... an excellent way of
editing a
form. I just have a few adjustments if any of you could
JSP:HTML Form in-place Editing - JSP-Servlet beans. Perhaps you guys are better aware of in-
place html form editing than me...JSP:
HTML Form in-
place Editing I have an
HTML form (
form #1) which...). Now my purpose is to re-populate the same customer
form (
form #1) based
Advertisements
Editing the ProfileEditing the Profile how to populate drop-down menu instead of text box in
editing the profile
restrict jtable editingrestrict jtable editing How to restrict jtable from
editing or JTable disable
editing?
public class MyTableModel extends AbstractTableModel {
public boolean isCellEditable(int row, int column
editing cell in a table - JDBCediting cell in a table how can i edit a cell in a table and save the change to a database Hi Friend,
Try the following code:
1)updateDatabase.jsp
RollNo
Name
Class
">
">
">
how to allow table editinghow to allow table editing 1**. hi... l've tried the method
isCellEditable(int rowIndex, int
colIndex) {
return true
but it doesn't enabled the user the
editing of any
cell why?????????????
regards
form form Can I prevent a
form from being submitted again
Inserting id in place of name to database this
form to another table and in
place of "name" of department I wanted to insert...Inserting id in
place of name to database Hello,
I have a database department where I have "id" and "name". I am fetching this data to a jsp
form ModuleNotFoundError: No module named 'place'ModuleNotFoundError: No module named '
place' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
place'
How to remove the ModuleNotFoundError: No module named '
place'
ModuleNotFoundError: No module named 'in-place'ModuleNotFoundError: No module named 'in-
place' Hi,
My Python... 'in-
place'
How to remove the ModuleNotFoundError: No module named 'in-
place... to install padas library.
You can install in-
place python with following
place reservation in plane place reservation in plane hi,how can i write a program in Java programming to
place reservation in air plane
from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane
best place to learn aibest
place to learn ai Hi,
I am beginner in Data Science and machine learning field. I am searching for
the tutorials to learn:
best
place... the
topic "best
place to learn ai". Also tell me which is the good
to use ArrayList in the place of Vectorto use ArrayList in the
place of Vector public Enumeration getInterfaces()
{
ISCMetaType currentType = this;
ArrayList allInterfaces = new ArrayList();
while( currentType != null
to use ArrayList in the place of Vectorto use ArrayList in the
place of Vector public Enumeration getInterfaces()
{
ISCMetaType currentType = this;
ArrayList allInterfaces = new ArrayList();
while( currentType != null
JavaScript where to place in HTML JavaScript where to
place in
HTML Where to
place JavaScript code into
HTML Code?
Placing JavaScript code into
HTML Code
In
HTML.... See the example given below.
Declaring JavaScript in
HTML Head Tag
<
ModuleNotFoundError: No module named 'place-api'ModuleNotFoundError: No module named '
place-api' Hi,
My Python... '
place-api'
How to remove the ModuleNotFoundError: No module named '
place... have to install padas library.
You can install
place-api python with following
Editing UI components using managed beanEditing UI components using managed bean Hello friends...
I want to edit the properties of a inputText on JSP page using its managed bean.
I have a simple inoutText and commandButton on jsp page and on click of button, i want
WANT TO RESTRICT EDITING AFTER A SET OF DATEWANT TO RESTRICT
EDITING AFTER A SET OF DATE localhost : Server version: 5.0.51b-community-nt
phpMyAdmin - 2.11.7
hello guys,
(adsbygoogle = window.adsbygoogle || []).push({});
i have to continue my work
best place to learn data sciencebest
place to learn data science Hi,
I am beginner in Data Science...
place to learn data science
Try to provide me good examples or tutorials links so that I can learn the
topic "best
place to learn data science"
best place to learn machine learningbest
place to learn machine learning Hi,
I am beginner in Data...:
best
place to learn machine learning
Try to provide me good examples or tutorials links so that I can learn the
topic "best
place to learn machine
best place to learn data analyticsbest
place to learn data analytics Hi,
I am beginner in Data...
place to learn data analytics
Try to provide me good examples or tutorials links so that I can learn the
topic "best
place to learn data analytics"
Place array of bytes in bufferPlace array of bytes in buffer
In this tutorial you will see how to
place array of bytes in buffer. The put
method of CharBuffer class transfers the entire content of the given source
character array into a buffer.
Code
Place array of double in a bufferPlace array of double in a buffer
In this tutorial you will see how to
place array of double in buffer. The put
method of
DoubleBuffer class transfers the entire content of the given source
double array into a buffer.
Code
form validationform validation how the
form validation is done in jsf
form using javaScript
About Nehru Place Market DelhiNehru
Place of New Delhi
Nehru
Place is one of the newer markets in New Delhi...
Place.
Nehru
Place was built in the southern part of the state of Delhi... buildings that had
been around when Nehru
Place first opened. Some concerns have come
What is the best place to learn Hadoop online?What is the best
place to learn Hadoop online? Hello,
I want to master Hadoop. What is the best
place to learn Hadoop online?
Thanks
Hi,
What is the best
place to learn Hadoop online?
Learning Hadoop gives
What is the best place to learn Hadoop online?What is the best
place to learn Hadoop online? Hello,
I want to master Hadoop. What is the best
place to learn Hadoop online?
Thanks
Hi,
What is the best
place to learn Hadoop online?
Learning Hadoop gives