Click here to Skip to main content
15,888,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am using a image on which i will click and open upload file control and get the file name into text box
<script type="text/javascript">
$(document).ready(function () {
$(document).on('change', '#<%= flUploadFile.ClientID%>', function (e) {

$('#<%= txtDetailFile.ClientID%>').val(e.target.files[0].name);

});

$('#<%=imgDetailFile.ClientID%>').click(function (e) {

$('#<%= flUploadFile.ClientID%>').trigger('click');

});
});
</script>

in this the file upload browser is opening but the file name not coming in text box and when i am using alert(""); then the file name is coming in textbox

So how can i take file name in to text box without alert

What I have tried:

<script type="text/javascript">
$(document).ready(function () {
$(document).on('change', '#<%= flUploadFile.ClientID%>', function (e) {

$('#<%= txtDetailFile.ClientID%>').val(e.target.files[0].name);
});

$('#<%=imgDetailFile.ClientID%>').click(function (e) {

$('#<%= flUploadFile.ClientID%>').trigger('click');
alert("");
});
});
</script>
Posted
Updated 12-Jun-18 6:50am
v3
Comments
Karthik_Mahalingam 28-May-16 4:29am    
What is the issue, your code is working fine..
Member 11083419 28-May-16 6:24am    
the issue is when i am clicking the imgDetailFile(img button) the file upload browser is open but the file name is not coming in textbox.........and when i am using alert(""); then after file name is coming in textbox .....i do't want alert(); simple file upload browser open and file name come in textbox
Karthik_Mahalingam 28-May-16 6:27am    
the file name will display after the file is selected.
post your exact code, coz i just copied your code and tested, it is working fine..

1 solution

Try this
Suppose following is your file upload control and textbox in which you want to show file name uploaded in file upload control.
ASP.NET
<asp:FileUpload ID="FileUpload1" runat="server" onchange="showFileName(this)" />
   <br />

       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


Following is java script code.

<script>
function showFileName(input) {
var file = $("#FileUpload1").val();

document.getElementById("TextBox1").value = file;
}
</script>


Simply write one function in java script and call this function on onchange of fileupload control.
 
Share this answer
 
v2
Comments
Member 11083419 30-May-16 8:04am    
@Veeshal Mali ,I mention in my question that i am using a image button on which i will click and it will take file upload control id and 'll open upload browser......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900