www.webdeveloper.com
Results 1 to 3 of 3

Thread: html file input not storing file

  1. #1
    Join Date
    Mar 2009
    Posts
    61

    html file input not storing file

    The jquery change event handler submits the form, but I noticed that it submits it without the file the user chose. The alert displays "file = ". Any ideas what's happening to the file?

    HTML Code:
    <form id='uploadForm' action='/FileTransferHandler.ashx' method='post', enctype='multipart/form-data'><button id='uploadButton' class='btn btn-primary'>Add Files</button><input id='fileToUpload' type='file' name='files[]' multiple='multiple' /></form>
    Code:
    $('#uploadButton').click(function() {
      event.preventDefault();
      $('#fileToUpload').click();
    });
    
    $('#fileToUpload').change(function() {
      var file = $('#fileToUpload').val();
      alert("file = " + file);
      //$('#uploadForm').submit();
    });

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    862
    As far as the code you posted goes, there are no problems. I can literally copy and paste that exact code into a new HTML file and it works.

    So if you are getting an empty value for the file <input> then it has to be related to something else. Have you checked the developer console? (Press F12 in your browser and then click on the 'Console' tab).
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    You had a typo (,) before the encoding type, possibly invalidating that attribute:

    Code:
    <form id='uploadForm' action='/FileTransferHandler.ashx' method='post' enctype='multipart/form-data'><button id='uploadButton' class='btn btn-primary'>Add Files</button><input id='fileToUpload' type='file' name='files[]' multiple='multiple' /></form>
    JavaScript: Learn | Validate | Compact | bionoid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles