Clearing file input box in Internet Explorer

file-upload, html, internet-explorer, javascript, jquery

Solution

It's readonly in IE8 onwards, so you can't clear it. The simplest way around this security feature is to replace the element with a copy.

Edit Found a previous answer to this that suggests the same approach! Clearing <input type='file' /> using jQuery

Problem

I have an file upload box and a clear button on my page. When I press the clear button, I want the text in the file upload box to be cleared. The following works in Firefox, but doesn't in IE (the text stays there). Is there a workaround for this? ``` $("#clear").click( function() { $("#attachment").val(""); //document.myform.attachment.value = ""; }) ``` HTML: ``` <form name="myform"> <input type="file" name="attachment" id="attachment" /> </form> <br /><button id="clear">Clear Attachment</button> ``` jsFiddle

Original source

Related problems