1

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.

7
  • code is correct..make sure your file variable is defined somewhere. Commented Jul 15, 2015 at 10:44
  • it's working jsfiddle.net/7b7bkyhd Commented Jul 15, 2015 at 10:45
  • @Kartikeya: Code is modified...still issue exists.. Commented Jul 15, 2015 at 10:45
  • Code is work here in jsfiddle. You should create a jsfiddle or use stack snippet that can reproduce the issue you met. Commented Jul 15, 2015 at 10:46
  • @Kartikeya yes, it works in jsfiddle but not on I.E [custom Page]... Commented Jul 15, 2015 at 10:52

2 Answers 2

0

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);
});
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.