Rakesh
Rakesh

Reputation: 2790

dynamic elements with multiple upload file

Hi I am using http://www.fyneworks.com/jquery/multiple-file-upload/ for multiple upload file. But I need the same feature for some dynamic file uploader also. so I crated a function addElement() for that. The problem is the dynamic element is creating correctly but multiple upload feature is not working.

<title>Add Element</title>
<script language="javascript">
this.num = 1;
function addElement(){
$top = document.getElementById('top');
newId = document.createElement('div');
id = 'my'+this.num;
newId.setAttribute('id', id );
newId.innerHTML = "<input type='file' name='DocumentFiles2' class='multi' />";
$top.appendChild(newId);
this.num++;
 }
function removedThis( id ){
var d = document.getElementById('top');
d.removeChild(id);
 }
</script>
</head>
<body>
<input type='file' name='DocumentFiles[]' class='multi' /><!-- This one is working -->
<input type="button" name="button" value="Add Element" onclick="addElement()"  />
<div id="top" ></div>
</body>
</html> 

There is any alternative way to do this or make this to work.?

Upvotes: 0

Views: 464

Answers (1)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Add this code after calling addElement and removedThis and check

function addElement(){
     .....
     .....
     reinit();
}
function removedThis( id ){
     .....
     .....
     reinit();
}
function reinit()
{
    $('input[name="DocumentFiles[]"]').MultiFile({
    // your code
    });
}

Upvotes: 2

Related Questions