ProfK
ProfK

Reputation: 51084

Why does my file input only accept one file?

I have the following Razor markup with a file input that I want to be able to select multiple files with:

<form asp-action="Upload">
    <input type="file" name="file" id="file" multiple onchange="javascript: updateFileList();" />
    <br />Selected files:
    <div id="fileList"></div>
    <div class="form-group">
        <input id="submitButton" type="submit" value="Upload" class="btn btn-default" />
        <a asp-action="Explorer" class="btn btn-default">Cancel</a>
    </div>
</form>

Yet each time I select one file, the input's value changed to only that file, i.e. it only lets me select one file at a time.

For the curious, the updateFileList function looks like this:

function updateFileList() {
    var input = document.getElementById('file');
    var output = document.getElementById('fileList');
    output.innerHTML = '<ul>';
    for (var i = 0; i < input.files.length; ++i) {
        output.innerHTML += '<li>' + input.files.item(i).name + '</li>';
    }
    output.innerHTML += '</ul>';
}

What is wrong here?

Upvotes: 1

Views: 1850

Answers (2)

ProfK
ProfK

Reputation: 51084

The problem is I was trying to select file after file by clicking the Choose Files button once for each file. If I click it only once and select multiple files in the file selection dialogue, it works fine.

Upvotes: 3

Balaji H P
Balaji H P

Reputation: 91

Check your updateFileList() function form me its working correctly

<input type="file" name="file" id="file" multiple onchange="javascript: updateFileList();" />

Upvotes: 2

Related Questions