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;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't the id in the getElementById function be the id of the file input button?
Sorry. You need to surround with a container and redraw that. I updated my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.