1

I'm using the input element in HTML with the file type option, IE: <input type="file" /> with the option of allowing multiple files to be selected.

However, I'm wondering if there's a way to remove or clear all of the files that the user selected via the file type button though a click of a button.

Basically, here is what I have so far:

<input type="file" multiple="multiple" />
<input type="button" value="Clear all attachments" onclick="" />

I have no idea how to implement that second button.

LOL. NO.
  • 577
  • 1
  • 6
  • 33

1 Answers1

3

There is a trick: Redraw the HTML block! Source

<div id="container">
   <input type="file" multiple="multiple" />
   <input type="button" value="Clear all attachments" onclick="clearSelection();" />
</div>

//Javascript
function clearSelection() {
    document.getElementById("container").innerHTML = document.getElementById("container").innerHTML;
}
haffla
  • 1,056
  • 8
  • 15