So I have this JS and it's working perfectly fine, but is it possible to change it from getElementById 'studentPhoto' into input type="file" instead?
Because I have many
<input type="file" id="studentPhoto">
<input type="file" id="studentPhoto">
Basically what I want to do is that the below JS will works in every studentPhotoId
document.getElementById('studentPhoto').addEventListener('change', checkFile, false);
function checkFile(e) {
var file_list = e.target.files;
for (var i = 0, file; file = file_list[i]; i++) {
var sFileName = file.name;
var sFileExtension = sFileName.split('.')[sFileName.split('.').length - 1].toLowerCase();
var iFileSize = file.size;
var iConvert = (file.size / 10485760).toFixed(2);
if (!(sFileExtension === "pdf" || sFileExtension === "doc" || sFileExtension === "docx") || iFileSize > 10485760) {
txt = "File type : " + sFileExtension + "\n\n";
txt += "Size: " + iConvert + " MB \n\n";
txt += "Please make sure your file is in pdf or doc format and less than 10 MB.\n\n";
alert(txt);
}
}
}
Thanks