Reputation: 2135
I'm working with java and using jstl in my jsp page. In my customer page, when I delete a customer, it will show a confirm box. But when I choose yes or no, it till delete this customer. This is my javascript code:
<a load-in="mainNotify" href='<c:url value="customer/delete?id=${ item.id }" />'
onclick="return confirm('Delete ?');">
<i class="icon-remove"></i></a>
How can I resolved this?
Upvotes: 1
Views: 2997
Reputation: 2411
The problem is that you're still dealing with a click to an a
element, and the browser behavior here is to navigate to the destination URL -- which in your case appears to be the delete action.
To prevent this, you need to cancel the click event if the user says "no" on the confirm
. So something more like:
The JavaScript:
function onDelete() {
if (!confirm('Delete?')) {
event.preventDefault();
}
}
The HTML:
<a load-in="mainNotify" href='<c:url value="customer/delete?id=${ item.id }" />' onclick="onDelete()">
<i class="icon-remove"></i></a>
Upvotes: 4