Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery auto upload file

I want the file input will automatic upload my image without enter any submit button.

<form action="/upload/" method="post" enctype="multipart/form-data">
  <input type="hidden" name="user_id" value="47" />
  <input type="file" name="upload" />
</form>

Let me know the trick with jQuery

like image 853
Blur Avatar asked Dec 18 '10 03:12

Blur


People also ask

How do I upload an HTML file?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!

What is the extension of jQuery file?

jQuery Events Save the scripts. js file, and refresh index. html in the browser.


2 Answers

You can submit the form on the file input's onchange event, like this:

$("input[name=upload]").change(function() {
    $(this).closest("form").submit();
});
like image 143
karim79 Avatar answered Sep 21 '22 05:09

karim79


With more recent versions you can also just set the autoUpload option to true:

$('#fileupload').fileupload({ autoUpload: true });
like image 26
lambinator Avatar answered Sep 22 '22 05:09

lambinator