Note that there are some explanatory texts on larger screens.

plurals
  1. POGet row id from database using checkboxes
    primarykey
    data
    text
    <p>I'm trying to delete a row from my MS access database using checkboxes. I have the database outputted to my JSP page, each row has a checkbox. I'm having trouble getting the rowId and also linking each checkbox with a row. Any help would be much appreciated. Thanks. </p> <pre><code>&lt;%@ page import="java.io.*,java.util.*,java.sql.*"%&gt; &lt;%@ page import="javax.servlet.http.*,javax.servlet.*" %&gt; &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt; &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;DELETE Operation&lt;/title&gt; &lt;script&gt; checkboxes = document.getElementsByTagName("input"); for (var i = 0; i &lt; checkboxes.length; i++) { var checkbox = checkboxes[i]; checkbox.onclick = function() { var currentRow = this.parentNode.parentNode; var secondColumn = currentRow.getElementsByTagName("td")[1]; alert("My text is: " + secondColumn.textContent ); }; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;sql:setDataSource var = "bookdB" scope = "session" driver = "sun.jdbc.odbc.JdbcOdbcDriver" url = "jdbc:odbc:bookdB" /&gt; &lt;c:set var="empId" value="103"/&gt; &lt;sql:update dataSource="${bookdB}" var="count"&gt; DELETE FROM Employees WHERE Id = ? &lt;sql:param value="${empId}" /&gt; &lt;/sql:update&gt; &lt;sql:query dataSource="${bookdB}" var="result"&gt; SELECT * from Employees; &lt;/sql:query&gt; &lt;table border="1" width="100%"&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;Emp ID&lt;/th&gt; &lt;th&gt;First Name&lt;/th&gt; &lt;th&gt;Last Name&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &lt;/tr&gt; &lt;c:forEach var="row" items="${result.rows}"&gt; &lt;form method="post" action="reserve.jsp"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type = "checkbox" value="reserve"&gt;&lt;/td&gt; &lt;td&gt;&lt;c:out value="${row.id}"/&gt;&lt;/td&gt; &lt;td&gt;&lt;c:out value="${row.first}"/&gt;&lt;/td&gt; &lt;td&gt;&lt;c:out value="${row.last}"/&gt;&lt;/td&gt; &lt;td&gt;&lt;c:out value="${row.age}"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/form&gt; &lt;/c:forEach&gt; &lt;input type = "submit" value="Delete"&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><img src="https://i.stack.imgur.com/WcGAC.png" alt="MS access database screenshot"></p> <p><img src="https://i.stack.imgur.com/A62Re.png" alt="image 2"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload