vkGunasekaran
vkGunasekaran

Reputation: 6814

How to keep existing file selections on multiple selections

In html we can select multiple files at once using file input control. But when i selected a file second time previous files overwritten by the newly selected files.

My question is, Can we able to keep existing file selections while selecting new files?

Upvotes: 1

Views: 464

Answers (2)

vkGunasekaran
vkGunasekaran

Reputation: 6814

I didn't get any snippet related to this, seems most people doesn't require this kind of functionality. So i did it myself.

  • created a file input control
  • click event on this element, clones current file input with duplicate id using jquery clone method. This cloned input control set to hidden and current input control holds latest files.
  • so, on form submit i got all the files selected

I doubt how well this method works in older browsers, but current chrome and firefox executes it well.

Upvotes: 1

Fred
Fred

Reputation: 2468

I think your problem is that you give the same name to the different <input> tags.

<div id="selectFiles">
    <input type='file' name='userFile1'>
    <input type='file' name='userFile2'>
    <input type='file' name='userFile3'>
    <input type='file' name='userFile4'>
</div>

Upvotes: 0

Related Questions