Using Chrome and Internet Explorer I am finding the following problem related how to obtain the file name inserted into an input tag using jQuery.
So I have the following situation: into a page I have this input tag:
<input id="rendicontoAllegato" class="form-control" style="height: 30px; padding: 0px;" type="file">
And a div having id="nomeDocumentoRendicontazione" that will contain the name of the file selected into the previous input tag:
<div id="nomeDocumentoRendicontazione"></div>
And associated to the change event of this input file I have this jQuery script:
$(document).ready(function() {
// When the user select a new fine into the input tag:
$("#rendicontoAllegato").change(function() {
// Retrieve the name of the selected file and put it into the hidden div having id="nomeDocumentoRendicontazione":
var selectedFileName = $("#rendicontoAllegato").val();
$('#nomeDocumentoRendicontazione').text(selectedFileName);
});
});
As you can see the previous script when the user select a new fine into the input tag change the value into the div having id="nomeDocumentoRendicontazione".
Using FireFox it works fine and if I select a file name cat.jpg in the div I have the value cat.jpg.
But if I use Chrome or Internet Explorer, after the file selection in the div I have the following value C:\fakepath\cat.jpg
Why? How can I obtain only the file name and not the **C:\fakepath** before it using Chrome and Internet Explorer