I found this question, but they did not answer it: Is there a jQuery event that I can control if the form cancellation is canceled?
So, if the user submits the form, and when the user loads, "esc" is pressed or the "stop" button of the browser is pressed, I want to call the function, is this possible?
Note. I know that we can bind the esc button, but what about the user stopping the browser from sending the stop / cancel button?
Is JavaScript or jquery solution possible?
EDIT:
I know that we can handle this problem with XHR (json / ajax), but I am looking for the usual form submission.
Just what I'm trying to achieve is this: when the user clicks the submit button, I want to disable the submit button. If the user canceled / paused the feed during the download, the submit button will still be disabled (should be turned back on if sending was canceled / stopped).
Change / rephrase - December 16, 2013:
My problem is similar to this: Is there a jQuery event that I can control if the form submission is canceled?
For example, I have this form:
<form method="post" enctype="multipart/form-data"> <input type="file" name="imginput" value=""/> <input type="text" name="textinput" value=""/> <input type="button" id="submitbtn" value="Submit"/> </form>
Here is the problem scenario:
A new user fills out a form, then double-clicks the submit button. The same form values ββare inserted into the server twice!
Attempt to achieve:
I want to disable the submit button when I click $('#submitbtn').bind('click', function() { $(this).attr('disabled','disabled'); $(this).prop('disabled', true); }); , which solves the problem, but creates another problem: if the user pressed "esc" or stopped the browser while the form is still submitted, the "Submit" button will still be disabled and the user cannot resend the form anymore, I want to enable the submit button again as soon as the "sending process" is canceled. Is there any way to achieve this? Something like: $(window).onStop(function() { ... }); ? or a way to indicate that the feed has been interrupted (or is still running)?
Notes:
- Looking for a client-side solution (javascript or jquery). I know that it can be easily solved by checking on the server side for identical records, but I'm not interested in the server solution.
- The problem can be solved with XHR bindings (ajax / json) (e.g. onSuccess, onFailure, etc.) .. but in this case I use a regular post, not XHR, so please exclude XHR from your answer.
- The solution should solve the problem for at least 5 major browsers (IE, FF, Chrome, Safari, Opera).
- Some might suggest that we bind "keypress" to the "esc" button, so when the user presses "esc", we turn on the submit button again. This is good, but it is a half-solution. What if the user stopped the βsend processβ with the browser stop button, is there a way to indicate that this stop button is pressed?