dave dave - 1 year ago 112
HTML Question

how to change the file input's filelist

I have this

of type
, and I want to change its
list. Example:

<input type = "file" id = "fileinput" />
<script type = "text/javascript>
document.getElementById("fileinput").files = [10];

The problem is that the
list is not set. How do I do it?

Answer Source

For security reasons, browsers prevent javascript from changing the files which will be uploaded: only the user can select files via the user interface. This is to prevent an evil script to upload /etc/passwd, for example, without the user knowing.

The one exception is that calling "reset" on the form will clear the file or filelist, but you can never add to programmatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download