Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I 'unselect' a selected file?

I'm using this to allow the user to select and upload a file:

<input id="fileInput" type="file" ng-file-select="onFileSelect($files)">

This correctly show:

enter image description here

When user clicks 'Upload', I upload the file.

When the user clicks 'Remove', how do I clear out the file name?

like image 955
Jason Avatar asked Aug 22 '14 08:08

Jason


1 Answers

Simply clear the value of the file input element:

document.getElementById('remove').addEventListener('click', function () {
    document.getElementById('fileInput').value = ''
});

Here's a demo

like image 60
raam86 Avatar answered Oct 04 '22 20:10

raam86