15

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

2 Answers 2

18

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

$("input[name=upload]").change(function() {
    $(this).closest("form").submit();
});
Sign up to request clarification or add additional context in comments.

2 Comments

wonderful jquery ;) if possible how do I display loading bar while uploading until it done?
Got it ;) $("#upload").change(function(){$(this).closest("form").submit();$('#loader').show();$(this).hide();});
7

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

$('#fileupload').fileupload({ autoUpload: true });

1 Comment

In the file js/main.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.