I'm trying to create a button that calls the event of a "file" type input, so that the input itself isn't displayed and I can style the button how I want to, following this post. The form is looking like this:
<form action="imageUpload.php" method="post" enctype="multipart/form-data" >
<input type="file" id="selectedImage" style="display: none;" onchange="this.form.submit()" />
<button onclick="document.getElementById('selectedImage').click();" />
</form>
When I click the button, the fileselect dialogue pops up, but the "imageUpload.php" is already called before a file is picked. However, when I take out the middle man by removing the button and displaying the input itself, it works as intended: "imageUpload.php" is called after a file is selected.
I'm assuming that the ".click();" function triggers "onchange", even though the value doesn't change. Is this correct? Is there any way to trigger the fileselect dialogue from another button without immediately calling onchange? Or is there a way to check whether a file was selected in onchange?
Thanks in advance.