Run form by clicking a browser button

Asked

Viewed 102 times

0

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

inserir a descrição da imagem aqui

When I choose a file and press "OPEN" I need my form to be sent 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>
  • 1

    Gives an Submit in the format when the file input changes

  • 1

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

  • It worked, if you want to put as an answer for me to mark just put there.

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()
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.