Reputation: 2313
I'm using jQuery MultiFile plugin, this is a ordinary view of that plugin
this is the HTML syntax for this
<input type="file" id="someName" name="file" class="multi" onchange="return Plugins.handleFileSelect(this);"/>
I'm trying to generate this file input dynamically
So I tried to append this once "click here" button click happens
<button type="button" id="ifile">click here</button>
<div id="target_div"></div>
<script type="text/javascript">
$('#ifile').click(function () {
// when the add file button is clicked append
// a new <input type="file" name="someName" />
// to a target_div div
$('#target_div').append(
$('<input/>').attr('type', "file").attr('name', "file").attr('id', "someName").attr('class', "multi").attr('onchange', "return Plugins.handleFileSelect(this);")
);
});
</script>
but once I do this its generating ordinary file input but its not listing files properly
once I open inspect elements I can see a view like following
how can I generate this properly
Upvotes: 0
Views: 7325
Reputation: 757
You should use MultiFile plugin instead
$('#ifile').click(function () {
// when the add file button is clicked append
// a new <input type="file" name="someName" />
// to a target_div div
var input = $('<input/>')
.attr('type', "file")
.attr('name', "file")
.attr('id', "someName");
//append the created file input
$('#target_div').append(input);
//initializing Multifile on the input element
input.MultiFile();
});
Upvotes: 2
Reputation: 414
you can use append like this
$('#target_div').append('<input type="file" id="someName" name="file" class="multi" onchange="return Plugins.handleFileSelect(this);"/>')
btw you can check the jquery documentation for append
Upvotes: 0