Andrew O Neill Andrew O Neill - 1 year ago 67
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?

Answer Source

Use this simple code

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download