get field type file js and loop

Solutions on MaxInterview for get field type file js and loop by the best coders in the world

showing results for - "get field type file js and loop"
Dido
25 Jul 2020
1// For multiple
2$("#my-form").find("input[type=file]").each(function(index, field){
3  for(var i=0;i<field.files.length;i++) {
4    const file = field.files[i];
5    if(file.size > 5242880 || file.fileSize > 5242880) {
6      errorMessage = 'Files must be less than 5MB.';
7      alert(errorMessage);
8    }
9  }
10});
Jessica
18 Nov 2017
1$("#my-form").find("input[type=file]").each(function(index, field){
2   const file = field.files[0];
3   if(file.size > 5242880 || file.fileSize > 5242880) {
4      errorMessage = 'Files must be less than 5MB.';
5   }
6});