How to edit the value of an input field of type file using Javascript/JQuery?
<p>I have seen numerous posts on this stating that for security reasons you cannot do so. For example, see <a href="https://stackoverflow.com/questions/17861340/how-to-change-value-to-an-input-field-of-type-file-using-jquery">this</a> Stackoverflow post and <a href="https://stackoverflow.com/questions/16595657/how-to-delete-the-value-of-an-input-type-file">this</a> one too. I do not want to reset the input file field. I merely want to delete some files from the selected ones. The deletion in the UI occurs out of the form field. For example, on change event, I refresh a div with the info on the selected fields. The user can change the content of this div by deleting certain entries. How do I then reflect it in the display in the input field itself where is says "3 files" or "2 files" or whatever depending on the number of files selected?</p>

<p>I tried this:   </p>

<pre><code> $('#fileField')[0].files
</code></pre>

<p>Where fileField is the id of a input field of type file. Let us say that the user has selected 3 files. I tried to simply delete one of them through, for example:</p>

<pre><code>   delete $('#fileField')[0].files[1]
</code></pre>

<p>I would expect that there will be two files now for that field. Does not work. </p>

<p>A bit more details on what I am doing...</p>

<p>I am using formdata object as in new FormData() and then appending files from the form input fields, as in: </p>

<pre><code> var fd = new FormData(), fileData;
 $('#' + myForm + ' input[type="file"]').each(function(index) {
    fileData = $(this)[0].files;
    if ($(this).attr('multiple')) {
       for (var i = 0; i&lt;fileData.length; ++i)
         fd.append($(this).attr('name')+"__"+i, fileData[i]);
       }
    ...
</code></pre>

<p>I can allow the user to manipulate the entries in the auxiliary div and skip any file to be sent to the server by not appending the ones deleted.  Problem is that I need to have the "2 files" or "3 files" or whatever that is displayed in the input field, after selection of multiple files, also be changed to accurately reflect the entries deleted in the div. How do I do this?  I know many plugins do this. Using one is not an option.</p>