Javascript, count how many files were attached to a file upload input

11,113

Solution 1

Try this code:

var numFiles = $("input:file")[0].files.length;

Solution 2

you may try this too

document.forms["form_name"]["multi_files_input_name[]"].files.length
Share:
11,113

Related videos on Youtube

Paranoid
Author by

Paranoid

I think too much.

Updated on June 21, 2022

Comments

  • Paranoid
    Paranoid almost 2 years

    I have this file input:

    <input type="file" name="photo[]" multiple="yes">
    

    What I want is, when someone uploads a file/files to it, I want to alert them how many files were uploaded (altogether). Like if I upload 3 files, it will alert "3 files were uploaded". And if I add 2 more files it will alert "5 files were uploaded" (adding the 2 files uploaded before).

  • Rijo
    Rijo about 7 years
    its more accurate than previous