I have three inputs in my form to upload file User can select n number of inputs to upload from 1 - 3 i want to made a check that not files is above the mentioned size file so i have used the following Script:
var fileInput = $('.registration_file');
var maxSize = fileInput.data('max-size');
$('#companyRegForm').submit(function(e){
if(fileInput.get(0).files.length){
var fileSize = fileInput.get(0).files[0].size; // in bytes
if(fileSize>maxSize){
alert('Dateigröße ist mehr dann ' + maxSize + ' bytes');
return false;
}
}
});
And mu Inputs are like:
<input accept=".jpeg,.pdf" data-max-size="500000" name="image_file_1" class="registration_file" type="file">
<input accept=".jpeg,.pdf" data-max-size="500000" name="image_file_2" class="registration_file registration_file_2" type="file">
<input accept=".jpeg,.pdf" data-max-size="500000" name="image_file_3" class="registration_file registration_file_3" type="file">
But in this case just first input is working other two are not validating and submit as it is without checking the file size,
That i need to do with this.