0

I have a filelist as show here. I would like to add another file to that list.

I've tried this but it doesn't add the file:

var newFileOnList = //...

// fileInput is an HTML input element: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");
var files = fileInput.files;

files.push(newFileOnList);

Edit:

I could even replace the list too, but this doesn't work either:

var newFileList = //...

// fileInput is an HTML input element: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");
fileInput.files = newFileList;
Grammin
  • 11,808
  • 22
  • 80
  • 138
  • 1
    Only the client can select files, and this must be done manually. In _HTML5_, you can ask the user for multiple files with a `` – Paul S. Aug 01 '13 at 21:16
  • This is on the client, its in my javascript code. And I know I can add more then one file using the multiple tag... The file I need to add is coming from elsewhere on the client. – Grammin Aug 01 '13 at 21:17
  • Perhaps you should consider using _XMLHttpRequest_, for example as described [**here**](http://stackoverflow.com/questions/2198470/javascript-uploading-a-file-without-a-file) – Paul S. Aug 01 '13 at 21:20
  • Not sure how to append files to the files array, but have a look at the formdata object, which you can definitely append files to and ajax off: https://developer.mozilla.org/en-US/docs/Web/API/FormData – xdl Aug 01 '13 at 22:51

0 Answers0