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.

1

1 Answer 1

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;
}
2
  • Shouldn't the id in the getElementById function be the id of the file input button?
    – LOL. NO.
    Commented Jul 6, 2015 at 21:35
  • Sorry. You need to surround with a container and redraw that. I updated my answer.
    – haffla
    Commented Jul 7, 2015 at 19:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.