Detect when user selects file using file input

How to determine when a user has selected a file to upload using html file input. This way I can submit the form automatically.

+4
source share
2 answers

The file upload element fires an onchange event when its contents have changed. Here is a very brief example:

<input type="file" name="whatever" onchange="alert('Changed!');" /> 

EDIT: Oh, and if you want to submit the form when they select something (although this will probably confuse your users a bit):

 <input type="file" name="whatever" onchange="this.form.submit();" /> 
+11
source

to try

 $('#inputfileID').change(function(){ alert(0); })​ 
+9
source

Source: https://habr.com/ru/post/1315272/


All Articles