Andrew O Neill Andrew O Neill - 10 days ago 5
HTML Question

How to access file upload selected file without changing page using javascript?

I need to create a file upload field which I have below:

<div class="col-xs-4 col-md-4 form-group">
<label for="file-upload" >File Upload</label>
<input type="file" id="file-upload"/>

How do I access the contents of the selected file without going to another page or adding anything to the URL in Javascript?


Use this simple code

var inputFile = document.getElementById("file-upload");

inputFile.addEventListener("change", function(){
    var files = inputFile.files;
<input type="file" id="file-upload"/>