gates
gates

Reputation: 4593

Auto submit does not get triggered

I want the file to be auto submitted to the form, once the user selects a file. I don't want the user to click the submit button

Here is the html

<input id="upload-profile" style="-webkit-user-select: text;" type="file" name="profile_pic[attachment]">
<input type="submit" name="commit" value="submit" class="submit-profile-pic" style="-webkit-user-select: text;">     

Here is the jquery

$(document).ready(function(){
    $('#upload-profile').change(function(event) {
        /* Act on the event */
        console.log("it went inside the event");
        $('submit-profile-pic').click();
    });

});                     

I have tried both submit and click, both does not work .. how ever manually clicking the submit button submits the form .. can anyone help me out.

Upvotes: 0

Views: 29

Answers (1)

GreyRoofPigeon
GreyRoofPigeon

Reputation: 18123

You are missing a dot

$('submit-profile-pic').click();

Should be

$('.submit-profile-pic').click();

As an alternative you could also use

$('form').submit();

Note: if you have multiple forms on your page, use the class or id as selector.

Upvotes: 1

Related Questions