2

I have the following input type file with multiple attribute:

<input accept=".txt" id="File" multiple="" name="File" type="file" />

When I use jQuery to read the input value:

$("#File").val()

I selected from my PC, two files. If I call above function it returns:

C:\fakepath\1.txt

I expect to return 2 file values (I don't know, separated by comma or other separator).

1
  • 1
    The val() function return path of files separated by comma Commented Mar 18, 2014 at 13:23

2 Answers 2

3

You can use the files property like

var files = $("#File").prop('files')

then loop it and read the name property of the file

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

Comments

2

You could access the underlying DOM element:

var fileList = $("#File")[0].files;
for (var i = 0; i < fileList.length; i++) {
   // Do stuff
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.