Marc
Marc

Reputation: 219

submit form after selecting input file everytime a user clicks the input button

I have a form in an iFrame that I can not modify directly (it is on the same domain though) so I am using jQuery to do some things. Here's what I'm doing right now:

$('#staffels_uploaden_frame', window.parent.document).contents().find("input[type=file]").change(function() { 
        // select the form and submit
        $(this).closest("form").submit();
    });

I have a form with a file input and after you have clicked on the input button to select your file, the form is submitted and the file is uploaded. But, this works only once: if you press the input button again, the form is not submitted, eventhough I thought the .change event would cover this. Can I modify this code to make the form submit everytime you browsed for a file?

Upvotes: 0

Views: 640

Answers (1)

Marc
Marc

Reputation: 219

I solved this by putting the code above in the .load method. Like this:

$('#staffels_uploaden_frame', window.parent.document).load(function() {
        // select the file input (using a id would be faster)
        $(this).contents().find("input[type=file]").change(function() {
            // select the form and submit
            $(this).closest("form").submit();   
});

Upvotes: 1

Related Questions