I have the following input file tag:
<input type="file" id="handlerxhr1" />
In mozilla when I run the following jQuery code:
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
alert(input.files[0]);
});
I get response: [object File] (which is good).
But in IE I get 'input.files.0 is undefined'
What am I doing wrong?
I have the following input file tag:
<input type="file" id="handlerxhr1" />
In mozilla when I run the following jQuery code:
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
alert(input.files[0]);
});
I get response: [object File] (which is good).
But in IE I get 'input.files.0 is undefined'
What am I doing wrong?
Share Improve this question edited Dec 7, 2019 at 13:11 Cœur 38.7k26 gold badges203 silver badges277 bronze badges asked Feb 15, 2011 at 7:35 ShaneKmShaneKm 21.3k46 gold badges175 silver badges307 bronze badges 3- 1 try alert(typeof(input.files)); in IE – Umair A. Commented Feb 15, 2011 at 7:37
- It might be affected by the way IE handles JS differently than firefox. The click event you have putten on your upload button fires after the upload is done on firefox, and before its done on IE. – Jan Dragsbaek Commented Feb 15, 2011 at 7:38
- can't be. because click event i declared var input when document.ready and after it's loaded i click '#upload' button – ShaneKm Commented Feb 15, 2011 at 7:40
2 Answers
Reset to default 6IE doesn't support .files[0] property, whereas FF does. See http://www.w3/TR/FileAPI/ for more details
This seems good enough...
$(function() {
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
alert(input);
});
});
Not sure if your were after something like this though:
$(function() {
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
var x = $('input[type=file]:eq(0)');
alert(x);
});
});