Hi, I'm starting to learn Java EE - JSP / SERVLET and as for my learning progress, I'm trying to achieve this kind of web app but Im having problem with displaying the right selected row (TASK ID Column) from my table. It is populated from my oracle db. Im able to display my expected output correctly. But when I'm trying to get the selected row through clicking the corresponding button, I'm always getting the 1st row value, i.e. ID = '123456', no matter what Button I clicked, 2nd, 3rd, etc. It always display the 1st row. You can kindly see the image below. Hoping someone can guide me to my problem. Thanks.
Note: Apologies for my coding conventions and use of scriptlet, I may later use JSTL /EL after I got used to the basics of JAVA EE. Thanks.
EXPECTED OUTPUT:
To check if its getting the correct value, I used javascript to retrieve the value of TaskID.
PARTIAL JSP CODE: I've cut some part of codes, displaying only TASKID and APPROVE Button for checking value purposes.
`<%
String strQuery = "SELECT * FROM SIM_TEST";
try{
Connection conn = ConnectionProvider.getConn();
PreparedStatement ps = conn.prepareStatement(strQuery);
ResultSet rs = ps.executeQuery() ;
int status;
String getId;
while (rs.next())
{
String taskId = rs.getString("TASKID");
%>
<tr>
<td><%=taskId%></td>
<td><input type="button" id="btnApprove" value="Approve" />
<input type="hidden" id="getTaskId" onclick="getTaskId();" value="<%=taskId%>" />
</td>
</tr>
<%
}
}catch(Exception e){
e.printStackTrace();
}
%>`
And to check if its getting the value of hidden type when APPROVE button is clicked, I use javascript.
<script type="text/javascript">
function getTaskId(){
var id = document.getElementById('getTaskId').value;
alert(id);
}
</script>