I wrote a table in html which consists of 6 columns with 6th column as a delete button.The rows will gets updated dynamically.
Now my first question is how to delete a row when we click that rows delete button and even in the database also.
Second question is, there are check boxes with every row and a delete1 button on the top on the table. If I checked some rows in table and click the delete1 button then those records must be deleted in the database.
How can this be done.
The below is my jsp code.
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')"/><br>
<table id="dataTable" border="15" >
<tr><th colspan="6" align="center">Data</th></tr>
<tr>
<td><b></b></td>
<td><b>Institution Name</b></td>
<td><b>Location</b></td>
<td><b>Status</b></td>
<td><b>Edit</b></td>
<td><b>Delete</b></td>
</tr>
<%
Session ses=new Configuration().configure().buildSessionFactory().openSession();
Transaction tx=ses.beginTransaction();
Query q1=ses.createQuery("from RegisterPojo as rp");
List<Enumeration> l= q1.list();
for(int i=0; i<l.size();++i) {
RegisterPojo rp=(RegisterPojo)l.get(i);
System.out.println(rp.getInstName());
System.out.println(rp.getInstName());
%>
<tr>
<td><input type="checkbox" value="<%= rp.getNo()%>"></td>
<td><%= rp.getInstName()%></td>
<td><%= rp.getLocation()%></td>
<td><%= rp.getStatus()%></td>
<td><a href="register.jsp">Edit</a></td>
<td><INPUT type="button" value="Delete"/></td>
</tr>
<%
}
%>
</table>
NOTE: I saw these type of questions in stackoverflow and even in some other websites but they didn't match my case.
Try the tutorial at the following website:
http://viralpatel.net/blogs/dynamically-add-remove-rows-in-html-table-using-javascript/
As for adding or deleting content from a database, I imagine you would want table.rows[n].innerHTML or table.rows[n].innerText and use a select and delete query from the database.
If one particular column is used as your key in the database, then you can use table.rows[n].cells[key].innerHTML or table.rows[n].cells[key].innerText to get just that cell's values and then do your queries with that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.