Run form when you click a browser button

0

I have a form with an input file, and what I want to do is the following.

WhenIchooseafileandhit"OPEN", I need to submit my form by clicking "OPEN".

  

My form.

<form class="form5" method="POST" enctype="multipart/form-data">
    <input type="file" name="Foto_us_sn_user" value="" style="display: none;">
    <input id="Bot_trocar_img_perf" type="submit" name="Trocar_foto_us_botao" value="Trocar">
</form>

<script>
    $('img.img_perfil_trocar').click(() => {
        $('[name="Foto_us_sn_user"]').click();
    })
</script>
    
asked by anonymous 11.03.2018 / 16:38

1 answer

2

With JQuery you can do as Edson mentioned in the comments:

$('input').on('change', function(){
    $('form').submit()
})

And with pure JavaScript:

document.getElementById('input').addEventListener('change', function() {
    document.getElementById('form').submit()
})
    
11.03.2018 / 19:11