Reputation: 1936
I have a function that is triggered by an click event... when clicked the function should get some information from the dom object that the click originated in. All this works fine in firefox, but in IE8 it is not making it past the alert 3.
function handleFileSelect(docEventTrigger) {
alert('1');
if($('#tblListDocs tr input[value!=""]').length>0){
alert('2');
updateClicked(instanceID);
}else{
alert('3');
var docName, docVersion, docDate, docAuthor, formHTML, actionText, docActions, docResults, frmTarget, docRowCount;
var files = docEventTrigger.target.files;
alert('4');
for (var iCount = 0, f; f = files[iCount]; iCount++) {
alert('5');
STUFF HAPPENS HERE
document.forms["frmUploadDoc"].submit();
alert('6');
}
}
Upvotes: 0
Views: 263
Reputation: 66388
The target
attribute of event object is not cross browser. For IE, it should be srcElement
.
To make the code cross browser, get either of those who is defined:
alert('3');
var sender, docName, docVersion, docDate, docAuthor, formHTML, actionText, docActions, docResults, frmTarget, docRowCount;
sender = docEventTrigger.target || docEventTrigger.srcElement;
var files = sender.files;
alert('4');
That said, it won't help your specific case as explained in this other answer.
To avoid having to mess around with the event, you can pass the object itself:
<input type="file" onchange="handleFileSelect(this);" />
Then the function parameter will already be the file input itself. (Same as sender
in my above example)
Upvotes: 0
Reputation: 140230
IE8 (or IE9 for that matter) doesn't support any file APIs. It will throw an error in files[iCount]
for a property access attempt on undefined
value at latest.
Upvotes: 1