Coder Perfect

When a file is selected, how can I make an upload form auto-submit?


I have a straightforward file upload form. When a file is selected, how can I make it submit automatically? The user should not have to click the Submit button.

Asked by ram1

Solution #1

In the onchange event of your file input, simply call the submit method of your form.

document.getElementById("file").onchange = function() {

Answered by Alex Turpin

Solution #2

Just tell the file-input to automatically submit the form on any change:

This is how the solution works:

The following are some of the benefits of this solution:

Answered by slartidan

Solution #3

Using jQuery:

Answered by Samich

Solution #4

JavaScript with onchange event:

jQuery .change() and .submit():

Answered by Alex.K.

Solution #5

The quickest answer is

<input type="file" name="file" onchange="javascript:document.getElementById('form').submit();" />

Answered by xboz

Post is based on