Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS for clearing <input type = "file"> selections

Once the user chooses the file, I have a condition using html5 file api to check if the file size exceeds a 1mb.

function handleLimit(evt) {
   var files = evt.target.files; 
   f = files[0];
   console.log(f.size);
   if (f.size > 1048576) {
          /*JS for clearing form*/
   }
}

What would be the script I would want to run on my input tag to clear/ force the client to choose another file it once the handler knows that file is exceeding a certain size?

like image 712
Emanegux Avatar asked Dec 27 '22 03:12

Emanegux


1 Answers

 var _fileuploadcontrolId = document.getElementById("id");
            _fileuploadcontrolId.value = "";
            _fileuploadcontrolId.focus();
like image 168
PSR Avatar answered Jan 06 '23 15:01

PSR