Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6693303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:58:02+00:00 2026-05-26T05:58:02+00:00

I am using HTML5’s wonderful ‘multiple’ file select feature. <input type=file id=fileInput onChange=runTest() multiple>

  • 0

I am using HTML5’s wonderful ‘multiple’ file select feature.

<input type="file" id="fileInput" onChange="runTest()" multiple>

I would like to display the selected filenames below the input field and make it look pretty with CSS, however…

If I run a test JS function, that ‘alerts’ me of the input field’s value, it only shows one file regardless of me selecting 10.

function runTest() {
var fileInput = document.getElementById('fileInput').value;
alert("You selected: "+fileInput);
}

I was doing this for when I had a ‘single’ file input field and worked okay but now it’s ‘multiple’, it doesn’t like it.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:58:03+00:00Added an answer on May 26, 2026 at 5:58 am

    Well, it seems the value, or val(), returned by the element is the name of only the last file selected. To work around this, it might be wise to use the nature of the multiple-change events:

    $('input:file[multiple]').change(
        function(){
            $('ul').append($('<li />').text($(this).val()));
        });
    

    JS Fiddle demo.

    And either output the names to a list (as in the example), or append the latest value to an array, or, possibly, use/create hidden inputs to store the filenames as you feel would best suit your application.

    To access the file-names (as well as last modified date, file-size…) you can (tested in Chromium 12/Ubuntu 11.04) use the following:

    $('input:file[multiple]').change(
        function(e){
            console.log(e.currentTarget.files);
        });
    

    JS Fiddle demo.


    Edited to make the above slightly more useful and, hopefully, demonstrative:

    $('input:file[multiple]').change(
        function(e){
            console.log(e.currentTarget.files);
            var numFiles = e.currentTarget.files.length;
                for (i=0;i<numFiles;i++){
                    fileSize = parseInt(e.currentTarget.files[i].fileSize, 10)/1024;
                    filesize = Math.round(fileSize);
                    $('<li />').text(e.currentTarget.files[i].fileName).appendTo($('#output'));
                    $('<span />').addClass('filesize').text('(' + filesize + 'kb)').appendTo($('#output li:last'));
                }
        });
    

    JS Fiddle demo.

    The final code-block updated, due to changes in Webkit, Chrome 24 (though possibly from earlier), by nextgentech in comments, below:

    $('input:file[multiple]').change(
        function(e){
            console.log(e.currentTarget.files);
            var numFiles = e.currentTarget.files.length;
                for (i=0;i<numFiles;i++){
                    fileSize = parseInt(e.currentTarget.files[i].size, 10)/1024;
                    filesize = Math.round(fileSize);
                    $('<li />').text(e.currentTarget.files[i].name).appendTo($('#output'));
                    $('<span />').addClass('filesize').text('(' + filesize + 'kb)').appendTo($('#output li:last'));
                }
        });
    

    JS Fiddle demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using HTML5 email fields — <input type=email/> — a lot of UAs (user
Using HTML5 I have an input field that should validate against a dollar amount
Using HTML5 and the Site.Manifest file, is it at all possible to create a
using HTML5, would it be semantically correct to place an <article> element within a
I am using HTML5 audio tag to link to a WAV file, but it
I am using HTML5, and would like to speed up the creation and editing
Using HTML5 File API I am able to read text and XML files without
I am using HTML5 fillText method of canvas in my coding.It is working file
I am trying to load multiple files using HTML5. This is my code I
I'm experimenting with using html5 and css counters to number the figures in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.