I have encountered an issue while trying to submit a form using the onchange event of an input element with type file. The problem is that it submits an empty form even when a file has been chosen.
Here is the code snippet:
var form = document.createElement("form");
form.action="http://localhost:8084/upload/image";
form.method="post";
form.enctype ="multipart/form-data";
form.target="upload_target";
var input=document.createElement("input");
input.type="file";
input.accept="image/jpeg, image/gif, image/png";
input.onchange=function(ev){this.form.submit()};
form.appendChild(input);
The form submission works correctly when a submit button is clicked, but not when the state of the "file input" changes.
I am looking for a solution to make it work as intended. Any suggestions?