-1

When I want to upload an image on my website, the user chooses the image from his device via this: <input required name='imagee' type="file" accept="image/*"> But after choosing the image he needs to click on a SUBMITION-Button to start the upload of the Form: <button type='submit' class="user_bnt">Submit</button> Is it possible to start the SUBMIT action via the Input? So after he selected the image, submit (triggering my form method="POST") will start?

j08691
  • 204,283
  • 31
  • 260
  • 272
Zaind
  • 11
  • 3
  • 2
    so add onchange handler and call form submit? – epascarello Nov 07 '22 at 14:37
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+submit+when+file+changes+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Nov 07 '22 at 14:43

1 Answers1

0

You can use JavaScript for this. Use the onchange attribute and run .submit() on your form. Your form tag can look like:

<form id="yourform">
    <input required name='imagee' type="file" accept="image/*" onchange="document.getElementById('yourform').submit()">
</form>
Pr77Pr77
  • 44
  • 6