0

I am trying to add to a global variable in order to determine total file size from an ajaxfileupload. I've tried the two ways below but attachmentSize keeps returning NaN. I've tried an if statement that checks for isNaN false, but variable still set to NaN.

var attachmentSize;
function onUploadComplete(sender, args) {
    attachmentSize += args.get_fileSize();
    attachmentSize = attachmentSize + args.get_fileSize();
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
KFP
  • 699
  • 3
  • 12
  • 33

1 Answers1

2

Initialize attachmentSize to a number (say 0).

Also, if you expect args.get_fileSize() to be a string (and not a number), then you can use parseInt or parseFloat:

var attachmentSize = 0;
function onUploadComplete(sender, args) {
    attachmentSize += parseFloat(args.get_fileSize());
    attachmentSize = attachmentSize + parseFloat(args.get_fileSize());
}

Cheers!

kukkuz
  • 41,512
  • 6
  • 59
  • 95