In my setup, I have a Servlet, JSP page, and JavaScript. I pass a list from the servlet to the JSP, where it displays the results. Each result is shown in a table and includes a delete button. My goal is to retrieve the ID of the result I want to delete and display an alert with the value.
The ${delete} button is only visible when there is an active session. This is because, in the presence of a session, I include the following code snippet:
String delete = "<input id=\"${emp.id}\" type=\"button\" onclick=\"test()\" value=\"Delete\" class=\"btn\">";
Below is the JSP foreach loop:
<c:forEach items="${requestScope.product}" var="emp">
<table border='1' align='center' cellpadding="5" width="60%" class="products" cellspacing="0" style=" text-align: left; font-size: 13px; color: honeydew;">
<tr>
<td style="font-size: 10px; text-align: right">${emp.addDate}</td>
<td style="text-align: center;">${emp.manufacturer} ${emp.model} ${emp.screenSize}</td>
</tr>
<tr>
<td rowspan="7"></td>
</tr>
<tr>
<td>${emp.category}</td>
</tr>
<tr>
<td>${emp.manufacturer}</td>
</tr>
<tr>
<td>${emp.model}</td>
</tr>
<tr>
<td>${emp.screenSize}</td>
</tr>
<tr>
<td>${emp.amountInStock}</td>
</tr>
<tr>
<td rowspan="2" style="text-align: right; font-size: 20px; font-style: italic;">${emp.price}</td>
</tr>
<tr>
<td style="font-size: 10px;">ID: ${emp.id} ${emp.editDate}</td>
</tr>
</table>
${delete}
<hr>
</c:forEach>