javascript - submitting when onchange event is triggered on an input element with type "file" -
i trying submit form using onchange event of input element type file problem empty form submitted instead though file chosen.
here code:
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 submits correctly when submit button clicked not when state of "file input" changed.
is there way achieve trying do?
are getting error?
you have syntax error. line:
input.onchange=function(ev){this.form.submit());
should be
input.onchange=function(ev){this.form.submit()};
also, browser using, because technique hook event won't work in of them (like non-modern ie :))
Comments
Post a Comment