JSP:HTML Form in-place Editing

Ads
 

JSP:HTML Form in-place Editing

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.
View Answers

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

November 7, 2011 at 1:36 AM

I have a que... If database has been created in access then we can follow the same code.............???

Ads









Related Tutorials/Questions & Answers:
how to check the radio button automatically depending up on the value of database when editing the form...
of database when editing the form...  hi...in my application i am editing the form and in that form the data in the database should come but icant be able... from database and display in the html table. At each row, there is a radio
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.  I am...;/script> <form name="form" method="post" action="http://localhost
Advertisements
Editing the Profile
Editing the Profile  how to populate drop-down menu instead of text box in editing the profile
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends AbstractTableModel { public boolean isCellEditable(int row, int column
how to allow table editing
how 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
ModuleNotFoundError: No module named 'mass_editing'
ModuleNotFoundError: No module named 'mass_editing'  Hi, My Python... 'mass_editing' How to remove the ModuleNotFoundError: No module named 'mass_editing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'media_editing'
ModuleNotFoundError: No module named 'media_editing'  Hi, My... 'media_editing' How to remove the ModuleNotFoundError: No module named 'media_editing' error? Thanks   Hi, In your python
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 '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
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 'odoo10-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo10-addon-mass-editing'  Hi...: No module named 'odoo10-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo11-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo11-addon-mass-editing'  Hi...: No module named 'odoo11-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo11-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo11-addon-mass-editing'  Hi...: No module named 'odoo11-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo12-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo12-addon-mass-editing'  Hi...: No module named 'odoo12-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo12-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo12-addon-mass-editing'  Hi...: No module named 'odoo12-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo12-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo13-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo13-addon-mass-editing'  Hi...: No module named 'odoo13-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo13-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo8-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo8-addon-mass-editing'  Hi...: No module named 'odoo8-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-mass-editing' error? Thanks  
ModuleNotFoundError: No module named 'odoo9-addon-mass-editing'
ModuleNotFoundError: No module named 'odoo9-addon-mass-editing'  Hi...: No module named 'odoo9-addon-mass-editing' How to remove the ModuleNotFoundError: No module named 'odoo9-addon-mass-editing' error? Thanks  
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
to use ArrayList in the place of Vector
to 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 Vector
to 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
ModuleNotFoundError: No module named 'pull_into_place'
ModuleNotFoundError: No module named 'pull_into_place'  Hi, My... named 'pull_into_place' How to remove the ModuleNotFoundError: No module named 'pull_into_place' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pull_into_place'
ModuleNotFoundError: No module named 'pull_into_place'  Hi, My... named 'pull_into_place' How to remove the ModuleNotFoundError: No module named 'pull_into_place' error? Thanks   Hi, In your python
Editing UI components using managed bean
Editing 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 DATE
WANT TO RESTRICT EDITING AFTER A SET OF DATE  localhost : Server version: 5.0.51b-community-nt phpMyAdmin - 2.11.7 hello guys, i have to continue my work more complex.. but i dont have any idea to do that... i want
form validation
form validation  how the form validation is done in jsf form using javaScript
ModuleNotFoundError: No module named 'django-geonames-place'
ModuleNotFoundError: No module named 'django-geonames-place'  Hi...: No module named 'django-geonames-place' How to remove the ModuleNotFoundError: No module named 'django-geonames-place' error? Thanks   Hi
ModuleNotFoundError: No module named 'google-place-id'
ModuleNotFoundError: No module named 'google-place-id'  Hi, My... named 'google-place-id' How to remove the ModuleNotFoundError: No module named 'google-place-id' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'google-place-id'
ModuleNotFoundError: No module named 'google-place-id'  Hi, My... named 'google-place-id' How to remove the ModuleNotFoundError: No module named 'google-place-id' error? Thanks   Hi, In your python

Ads