I have to show the details of files(filesize,filename) selected to upload in the table once the file is selected to upload.I'm able to show the details of one file selected, but if the user select second file, a second row in the table should be added dynamically and show the details of second file selected and should display the serial number in "sno" column in the table.Even user can select multiple files at a time but each file details should be shown in individual row of the table. http://jsfiddle.net/f38cB/ Below is the code: JSP Code:
<input type="file" name="fileUpload" size="50" id="file1" multiple/>
<table border="1" id="uploadTable" style="visibility:hidden">
<tr> <th>SNo</th><th>FileName</th><th>FileSize</th><th>Action</th> </tr>
<tr><td><input type="text" name="sno" id="sno"/></td>
<td><input type="text" name="fileName" id="fileName"/></td>
<td><input type="text" name="fileSize" id="fileSize"/></td>
<td width="100%"><a href="">delete</a></td>
</tr>
</table>
JavaScript code:
document.getElementById("file1").onchange = function() {
document.getElementById("uploadTable").style.visibility="visible";
var file = this.files[0];
document.getElementById("fileSize").value = file.size + " bytes";
document.getElementById("fileName").value = file.name;
};