How do I submit a "file" input without submit button using JavaScript?
yes, you can use the form.submit()
function. Add an onchange listener on the file input and link it to the form.submit()
function, like so:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" onchange="this.form.submit()" name="myFile"/>
</form>
Yes, you can add the following to the onchange
event of the file input:
<input type='file' .... onchange='this.form.submit();'>
this submits the form right after the user has picked a file. However, the user can't correct a mistaken selection before submitting - be sure to check whether this is really wise.