admin管理员组文章数量:1330619
I have a form which I'm using to upload files. In current situation if a user choose an image from his puter he have to click button upload to upload the image. I'm trying to find a way to skip the step with a button pressing.
How to call a javascript function when the file is selected from user ?
I have a form which I'm using to upload files. In current situation if a user choose an image from his puter he have to click button upload to upload the image. I'm trying to find a way to skip the step with a button pressing.
How to call a javascript function when the file is selected from user ?
Share Improve this question edited Feb 18, 2011 at 9:47 Bobby 11.6k5 gold badges47 silver badges70 bronze badges asked Feb 18, 2011 at 9:46 brodobrodo 651 gold badge2 silver badges5 bronze badges2 Answers
Reset to default 5The onchange
event is fired when a user specify a file for the upload filed. You could go about something like this:
<input type="file" name="someName" id="uploadID" />
Javascript:
var el = document.getElementById('#uploadID');
el.onchange = function(){
// your code...
};
However, javascript validation is good idea but make sure that you do the actual validation on the server-side :)
Using the example above...
<input type="file" name="someName" id="uploadID" />
JavaScript
document.getElementById('uploadID').addEventListener('change', () => {
//Your code...
});
本文标签: javascriptCall function on file uploadStack Overflow
版权声明:本文标题:javascript - Call function on file upload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742223332a2435593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论