1

I got code for input file:

<input type='file'/> 

When I selected a file from my directory, it shows file name beside choose button. Now, I'd to show all files that I choose. For example:

1.png

2.pdf

3.png

Note that (1, 2, 3 is file name)

How can I do that? Thanks.

2 Answers 2

2

You have to add a listener on the 'change' event of your input

Assuming your input id is 'inputFile'

document.getElementById('inputFile').addEventListener('change', onChange, false); function onChange(e){ var files = e.target.files; for (var i=0; i<files.length;i++) console.log(files[i]); } 
Sign up to request clarification or add additional context in comments.

Comments

1

Just use document.getElementById('inputfile').value; For example:

<input id="inputfile" type='file'/> <script> var filename=document.getElementById('inputfile').value; </script> 

or if you use multiple input use:

<input id="inputfile" multiple="multiple" type='file'/> <script> filenames = new Array(); for (var i=0; i<document.getElementById('inputfile').files.length; i++){ filenames.push( document.getElementById('inputfile').files[i].name); } </script> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.