Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  186] [ 4]  / answers: 1 / hits: 34055  / 13 Years ago, mon, august 8, 2011, 12:00:00

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


More From » jquery

 Answers
38

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


[#90734] Sunday, August 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;