I'm trying to show a confirm dialog before submitting form data. I want a dialog to pop up with ok and cancel where ok submits the data and cancel does nothing. This has proven to be trickier than I ever could have imagined.
The web application is in java and jsp. I've tried the following using "onclick=" hoping for a simple solution to no avail:
Java: ReceiveAction.java
public Resolution receiveInventory() {
...
return new ForwardResolution(ADJUSTMENT);
}
jsp: receive-action.jsp
<button name="_eventName" value="receiveInventory" type="submit" class="btn btn-green disabler-ignore-readonly" onclick="javascript:return confirm('are you sure?');">Receive</button>
The problem is I can get the confirm dialog to appear with the above code but receiveInventory is triggered whether I hit ok or cancel. I need it to only trigger when I hit ok. I feel like I'm very well versed in java and jsp but I'm less than a novice when it comes to javascript(I avoid it like the plague) and I think that's what I'm going to need to pull this off. Any help or pointing in the right direction would be greatly appreciated.