I am using Jquery Upload File Plugin. It seems perfect except that I am not sure how to make it work for dynamically added file upload controls. Documentation doesn't seem to have any such example.
<div id="container">
<div class="fileuploader">Upload</div>
</div>
<button id="btnadd">CLICK</button>
$(".fileuploader").uploadFile({
url: "YOUR_FILE_UPLOAD_URL",
fileName: "myfile"
});
$('#btnadd').on('click', function () {
$("#container").append('<div class="fileuploader">Upload</div>');
//-----if i uncomment this, it would work. But I want to avoid this.
// $(".fileuploader").uploadFile({
// url:"YOUR_FILE_UPLOAD_URL",
// fileName:"myfile"
// });
});
What you're doing is the one of the right ways of doing it as the plugin can't be bound to elements that do not exist when the page was first loaded. Here is another way of doing it, which is a bit cleaner (I think) using custom events. I have added inline comments where necessary to explain the code.