-1

Hi I am using Jquery plug in jquery.MultiFile.pack.js . usage of this plug in requires input form element to be of class "multi"

<input id="preview" class="multi" name="preview[]" type="file" />

I am adding form elements dynamically from a PHP script. Multi file upload is not working when the elements are added dynamically, but works when element is allready present directly in the .

My question is how do I make this multi file upload to work. I tried to add class "multi" to the elements usng "on" as below, but it is not working.

$('input:file').on('click',function(){
  $('#preview').addClass("multi");

});
s k nagesh
  • 98
  • 9
  • 1
    When you ask something, please add related code and other relevant information such as which plugin, link to the plugin documentation etc. – rrk Jun 30 '15 at 11:33

1 Answers1

0

For an HTML file input to accept a multiple file selection, you have to add it the multiple property :

<input id="preview" class="multi" name="preview[]" type="file" multiple/>
Remy Grandin
  • 1,638
  • 1
  • 14
  • 34
  • Is this multiple property part of HTML5?. So if I use multiple property I do not need to use any additional plugins. – s k nagesh Jun 30 '15 at 11:48
  • Yes it's an HTML5 property and it's supported by all major browsers. If you just need to have multiple file to upload in a form, then it's the best solution ! – Remy Grandin Jun 30 '15 at 11:54
  • I tried this, but it is not working for me. I am using jquery to submit the form and load the result on to a div. Will jquery serializeArray() handle this multiple property?. – s k nagesh Jun 30 '15 at 12:33
  • Do you just submit the form or do you send it by ajax ? if it's by ajax, you mus do some tweaking to your ajax request to be able to send files : http://stackoverflow.com/a/8758614/4734683 – Remy Grandin Jun 30 '15 at 12:40