1
votes

I have a file input control and button as below:-

<input type="file" name="Resume" id="upload"></input>
<input type="button" id="btnSave" value="Save" onclick="sample()"></input>

Also a function called as sample()

<script type="text/javascript">
    function sample(){
    var file =$('#upload')[0].files[0];
    alert(file);
    }
</script>

The above function is called on a click of button btnsave.

Issue:Does not return a alert with [object File], inspite of file exist in file input control.

Note: I am using I.E 11 and also loaded Jquery library.

2
code is correct..make sure your file variable is defined somewhere.Kartikeya Khosla
@Kartikeya: Code is modified...still issue exists..user5013815
Code is work here in jsfiddle. You should create a jsfiddle or use stack snippet that can reproduce the issue you met.fuyushimoya
@Kartikeya yes, it works in jsfiddle but not on I.E [custom Page]...user5013815

2 Answers

0
votes

The code works fine, here is a fiddle : https://jsfiddle.net/Ujwal_15/x5bgqqo7/6/

HTML:

<input type="file" name="Resume" id="upload" />
<input type="button" id="btnSave" value="Save" />

jQuery

$('#btnSave').click(function() {
    var file =$('#upload')[0].files[0];
    alert(file);
});
0
votes

You might be experiencing an issue in which the site you are working on is listed in your Local Intranet zone which causes IE to emulate an older version. Try adding this line as the very first entry within your <head> tag:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

From Microsoft: https://msdn.microsoft.com/en-us/library/jj676915.aspx