Search code examples
javascriptjqueryfile-uploadjquery-file-upload

Jquery File Upload Reset in Internet Explorer


I am using jquery in a classic asp webform. The form itself is basic and only uploads up to 5 files.

When uploading the files I have provided an option to users to delete one of the files from being uploaded. The jquery code I have used for this is

$('#delete_attachment').click(function() {
    if (confirm('Are you sure you want to delete this file?')) {
    $('#file_format').val('');//this is for a textbox and works fine
    $('#document_attachment').val('');//this is the line that deletes the file
    $('#document_comment').val('');//this is for a textbox and works fine too
    }
    });
});

This works perfectly fine in Chrome and the file is removed. However in Internet Explorer, the file remains and gets uploaded. Is there any other way to avoid the file from being uploaded and to delete it from the upload que using regular html file-upload control


Solution

  • You can't change the value of a file input type, because that would introduce a security vulnerability.

    Instead of $('#document_attachment').val(''); you can simply do:

    $('#document_attachment').replaceWith('<input name="file" type="file" id="document_attachment"/>');