I am making file input boxes through a javascrpit function, if the user wants to Attach more files, The function is
<script type="text/javascript">
var upload_number = 1;
var attachmentlimit = 5;
function addFileInput() {
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "attach[]");
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
if(upload_number == attachmentlimit) {
document.getElementById('moreUploadsLink').style.display='none';
}
}
</script>
I am also checking the size of the File input at client through javascript function,
<script type="text/javascript">
var myFile = document.getElementById('attach');
myFile.addEventListener('change', function() {
var size = this.files[0].size;
alert(size,'File Size Exceeds');
});
</script>
The problem is, the above javascript function, gives the Size alert of only the first File Upload box, and not the others. Any one who tell how to make this to provide sizes of all file uploads.
Add the event listener to the file
somewhere around d.appendChild(file)
. Otherwise, if you never tell JS to listen for the event, how can you expect it to?