Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulating the uploaded file name and size in a html table, appending new values when user choose files at second time
    primarykey
    data
    text
    <p>Question is i have table in which i want to populate the values of file name and file size after user click the choose file button and select any number of files, Now the issue is if the user click choose files button second time i want to append the new values in the table and add the new file in the array so that it can uploaded.. my code is,</p> <p><strong>html form code:</strong></p> <pre><code>&lt;form id="simpleuploadform" method="post" action="upload" enctype="multipart/form-data"&gt; &lt;table class="span10" border="0"&gt; &lt;tr&gt; &lt;td colspan="3"&gt; &lt;legend&gt;Simple Upload&lt;/legend&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="file" name="files[]" multiple="multiple" onchange="getFileSizeandName(this);"/&gt; &lt;div id="successdiv" hidden="true" class="label label-success"&gt;Image uploaded successfully&lt;/div&gt; &lt;div id="errordiv" hidden="true" class="label label-error"&gt;Image not successfully uploaded&lt;/div&gt; &lt;div id="streamdiv" hidden="true" class="label label-warning"&gt;Issue while uploading try again&lt;/div&gt; &lt;/td&gt; &lt;td id="renameFile" align="right"&gt;&lt;/td&gt; &lt;td id="removeFile" align="right"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt; &lt;div id="uploaddiv"&gt; &lt;table id="uploadTable" class="table table-striped table-bordered" width="200" height="200" scrolling="yes"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Size&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody id="tbodyid"&gt; &lt;tr id="tr0"&gt; &lt;td id="filetd0" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="filesizetd0" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr1"&gt; &lt;td id="filetd1" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="filesizetd1" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr2"&gt; &lt;td id="filetd2" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="filesizetd2" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr3"&gt; &lt;td id="filetd3" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="filesizetd3" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr id="tr4"&gt; &lt;td id="filetd4" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="filesizetd4" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;td id="filecount" height="10px" width="50px"&gt;&lt;/td&gt; &lt;td id="totalsize" height="10px" width="5px"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt; &lt;input type="submit" class="btn btn-primary" onClick="CloseAndRefresh();" value="Start Upload" id="startButton" disabled&gt; &lt;input type="reset" class="btn btn-primary" onClick="Clear();" value="Clear" id="clearButton" disabled&gt; &lt;input type="button" class="btn" onClick="window.close();" value="Close"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p></p> <p><strong>javascript code:</strong></p> <pre><code>&lt;script type="text/javascript"&gt; var totalsizeOfUploadFiles = 0; function getFileSizeandName(input) { var select = $('#uploadTable tbody'); $('#renameFile').empty();$('#removeFile').empty(); if(input.files.length &gt; 0) { $('#renameFile').append($('&lt;a id="renameRec"&gt;Rename Selected&lt;/a&gt;')); $('#removeFile').append($('&lt;a id="removeRec"&gt;Remove Selected&lt;/a&gt;')); $('#startButton').removeAttr("disabled", "disabled"); $('#clearButton').removeAttr("disabled", "disabled"); } //if(input.files.length &lt;= 5) //{ for(var i =0; i&lt;input.files.length; i++) { var filesizeInBytes = input.files[i].size; var filesizeInMB = (filesizeInBytes / (1024*1024)).toFixed(2); var filename = input.files[i].name; //alert("File name is : "+filename+" || size : "+filesizeInMB+" MB || size : "+filesizeInBytes+" Bytes"); if(i&lt;=4) { $('#filetd'+i+'').text(filename); $('#filesizetd'+i+'').text(filesizeInMB); } else if(i&gt;4) select.append($('&lt;tr id=tr'+i+'&gt;&lt;td id=filetd'+i+'&gt;'+filename+'&lt;/td&gt;&lt;td id=filesizetd'+i+'&gt;'+filesizeInMB+'&lt;/td&gt;&lt;/tr&gt;')); totalsizeOfUploadFiles += parseFloat(filesizeInMB); $('#totalsize').text(totalsizeOfUploadFiles.toFixed(2)+" MB"); if(i==0) $('#filecount').text("1file"); else { var no = parseInt(i) + 1; $('#filecount').text(no+"files"); } } //} } function CloseAndRefresh() { var daa = '&lt;%=status%&gt;'; if(daa == "true") $('#successdiv').show(); else if(daa == "false") $('#errordiv').show(); else $('#streamdiv').show(); opener.location.reload(true); self.close(); } function Clear() { $('#uploadTable tbody tr td').each(function(){ $(this).text(""); }); $('#uploadTable tfoot tr td').each(function(){ $(this).text(""); }); } </code></pre> <p></p> <p>i am trying to do as like this <a href="http://www.shutterfly.com/" rel="nofollow">http://www.shutterfly.com/</a> image upload.</p> <p>any help will be appreciated, thank you friends... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload