Disabling button during upload in a form?
I have a form with a button at the end where a user can Upload a file. I would like the button to be disabled when the user clicks the Upload button until the upload is complete. Would this be simple to imple开发者_如何学Pythonment?
Add this to the button.
onclick="this.disabled=true;"
Example:
<input type="submit" onclick="this.disabled=true;" />
I've never tried it before, but I think this topic could be useful: jquery/JavaScript - Delay until upload complete
Your solution has two parts. First, you want to disable the "Upload" button.
<form ... onSubmit="document.getElementById('fileThing').disabled = true;">
...
<input type="FILE" id="fileThing" size="40">
...
</form>
You can add the JavaScript part before any other JS that you might be running in that block (such as calling the AJAX script).
Next, you will need to put some code into your AJAX script that enables the button. The exact location will vary. I will assume that your AJAX script calls a function called whenComplete
when it receives the full response from the server. Add the following line into that function, along with any other after-request processing code:
document.getElementById('filething').disabled = false;
You will need to figure out where exactly this line needs to go, as we can't know how your AJAX script is set up without seeing the implementation itself.
精彩评论