0

I'm using jQuery MultiFile plugin, this is a ordinary view of that plugin

enter image description here

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

enter image description here

how can I generate this properly

2 Answers 2

2

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();
});
Sign up to request clarification or add additional context in comments.

1 Comment

your answer very accurate, I wish if you can answer this question too which is hide "No file choosen text in above multifile input" and I have another question which is shorten the lengthy label name in jQuery MultiFile
0

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

http://api.jquery.com/append/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.