when I define the file as a variable with jquery selector I get this error : Uncaught TypeError: Array.prototype.map called on null or undefined. if I use :
var file = document.getElementById('file'); instead of
var file = $('#file').val();
then it works, but I'm curious why using jquery selector doen't work. Thanks
$('#file').on('change', function(){ var file = $('#file').val(); var sizes = [].map.call(file.files, function(v) {return v.size;}); var totalSize = sizes.reduce(function(a, b) {return a + b;}, 0); });
valis going to give you the string value of the input, not a DomNode which is what getElementById will give you.