hkguile
hkguile

Reputation: 4369

jQuery bind file input dynamically and retrieve file in a function

I have a function will create a fileinput field for example

function addCol () {
   //add file input fields

   //last line of the function will bind all file input fields to a function
   $('#upload_'+rowNum[1]+'_'+colSize).bind('change', {fh:'upload_'+rowNum[1]+'_'+colSize}, readURL);
}

The function

function readURL(e) {
    alert(e.data.fh);
    var input = $('#'+e.data.fh);
    alert(input.files);
}

As a result,

e.data.fh = 'upload_1_1'
input.files = undefined

Anyone know how I can retrieve the file from the file input fields dynamically?

Upvotes: 2

Views: 412

Answers (1)

Zamboney
Zamboney

Reputation: 2010

try e.target.files[0] the e.target return the html tag <input type="file"> and in this tag there is a property call files that contain all of the files that been loaded

Upvotes: 1

Related Questions