views:

29

answers:

1

Hi,

I am using Multifile plugin to select the multiple file. I am trying to get the final file count for each browser selection . Any help is appreciated.

Here is the sample code i am using

<html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.MultiFile.js"></script>
<script>
var intVal=2;
$(document).ready(function(){
    $('#addFileButton').click(function(){addUploadFile();});
 });

function addUploadFile() {
intVal++;
$('<div id="addVal'+intVal+'">Please specify a file, or a set of files
(dynamically):<br>'+
   '<input type="file" class="multi" name="df'+intVal+'" id="df'+intVal+'"
size="40"/></div>').appendTo('#outerVal');
$('#df'+intVal).MultiFile();
}

</script>

<form action="doUpload" enctype="multipart/form-data" method="post">
<div id="outerVal">
<!--p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p-->
<div id="addVal1">
Please specify a file, or a set of files:<br>
<input type="file" class="multi" name="df1" size="40">
</div>
<div id="addVal2">
Please specify a file, or a set of files:<br>
<input type="file" class="multi" name="df2" size="40">
</div>

</div>
<div>
<input type="submit" value="Send">
<input type="button" class="button" value="Add File" id="addFileButton" />
</div>
</form>
</html> 
+2  A: 

You don't need the addUploadFile function, Multifile will take care of it for you. To keep a counter, just hook into onFileAppend and onFileRemove, like so:

HTML:

<input type="file" id="upload" name="upload" />

JS:

var count = 0;
$(document).ready (function () {
    $('#upload').MultiFile ({
        onFileAppend: function () { ++count; },
        onFileRemove: function () { --count; }
    });
});
K Prime