file upload not working in firefox
I have in my 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();
开发者_JS百科 });
$(function() {
$('#FileUpload').change(function() {
$("#MyTextBox").val($(this).val());
});
});
This means when the user click UploadFileButton
,the chose file select popup shows.
My problem is that my script works in Chrome but not in Firefox.
Any ideas please if someone has already encountered this problem.If you research this you find that in a lot of browsers triggering a click on the <input type='file' />
element is not allowed. It works in Chrome as long as the click is triggered by actual human interaction - even if the click event handler of another element triggers the click event on another. I'm only 90% sure about this, though.
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>
精彩评论