Reputation: 819
how to pass an id without using get method? only the post method..
here is my code having a get method:
<c:forEach var="student" items="${studentList}">
<tr>
<td><c:out value="${student.firstName}" /></td>
<td><c:out value="${student.middleName}" /></td>
<td><c:out value="${student.lastName}" /></td>
<td><c:out value="${student.yearLevel}" /></td>
<td><c:out value="${student.scholarship}" /></td>
<td><a href="student?page=edit&id=${student.id}">Edit</a></td>
<td><a href="student?page=delete&id=${student.id}">Delete</a></td>
</tr>
</c:forEach>
i tried to use
<input type="hidden" name="edit" value="${student.id}">
<input type="hidden" name="delete" value="${student.id}">
but the first student in list will always be edited and the first in the list of students will be deleted
Upvotes: 0
Views: 613
Reputation: 48837
If you are able to use jQuery, you could do something like that:
<script type="text/javascript">
$(function() {
$(".studentAction").off("click").on("click", function() {
var url = "student";
url += "?page=" + $(this).attr("name");
url += "&id=" + $(this).val();
$.ajax({
type: "POST",
url: url,
async: false,
success: function(data) {
// on success
},
error: function(data) {
// on error
}
};
});
});
</script>
<input class="studentAction" type="hidden" name="edit" value="${student.id}">
<input class="studentAction" type="hidden" name="delete" value="${student.id}">
Upvotes: 0
Reputation: 887777
You need to create a separate <form>
tag for each button.
Otherwise, all of your buttons will share all of the inputs in the form.
Upvotes: 1