File upload does not work in Firefox

I have an asp.net page

<input id="MyTextBox" runat="server" type="text" name="T1" size="20"/> <asp:Button ID="UploadFileButton" runat="server" Text="Upload" /> <input id="FileUpload" runat="server" type="file" style="height: 22px; visibility:hidden;" /> 

linked to JS script:

  $("#UploadFileButton").live("click", function(event) { event.preventDefault(); $("#FileUpload").click(); }); $(function() { $('#FileUpload').change(function() { $("#MyTextBox").val($(this).val()); }); }); 

This means that when the user clicks UploadFileButton , a pop-up window for selecting the selected file is displayed.
After the user has selected the file, the file path is MyTextBox = Selct.

My problem is that my script works in Chrome, but not in Firefox.
Any ideas please if someone has already run into this problem.

0
source share
2 answers

If you examine this, you will find that in many browsers, clicking on the <input type='file' /> element is not allowed. It works in Chrome until the click is triggered by real interaction with the person - even if the click event handler of another element raises a click event on another. I am only 90% sure of this.

0
source

I had the same problem, you can use this code:

 <input id="FileUpload" runat="server" type="file" style="height: 22px; onchange="fill();"/> <script language="javascript"> function fill() { $("#<%=MyTextBox.ClientID%>").val($("#<%=FileUpload.ClientID%>").val()) } </script> 
0
source

All Articles