gstackoverflow
gstackoverflow

Reputation: 37002

submit form as soon as file was selected

I have following html form:

<form method="POST"  action="uploadImage" enctype="multipart/form-data">
                        <input type="file" class="file" name="file"/>
                        <input type="submit" value="Upload">
    </form>

I see two things on page
1 - file selector
2 - upload button

I want to avoid submit button and form should be submitted right after file was selected.

Can you help me?

Upvotes: 2

Views: 293

Answers (2)

Sampath Liyanage
Sampath Liyanage

Reputation: 4896

with javascript..

<form method="POST" name="myform" action="uploadImage" enctype="multipart/form-data">
     <input type="file" class="file" name="file" onchange="document.forms['myform'].submit();"/>
</form>

Upvotes: 1

twain
twain

Reputation: 1325

Maybe this helps you:

$('.file').change(function(){
    $('form').submit();
});

Upvotes: 5

Related Questions