Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,

I have a File Upload and a Textbox field on my asp-page. Now I would like to create a button, that copies the name of the selected file into my textbox using javascript. How can I do that?

XML
<asp:FileUpload ID="f_file" runat="server" />
<asp:TextBox ID="f_text" runat="server"></asp:TextBox>
Posted

call following function on onclientclick of button
JavaScript
function setPath()
{     
    var objReg = new RegExp(/([^\/\\]+)$/);
    var strName = objReg.exec(document.getelementById("f_file").value);
    document.getelementById("f_text").value = strName[0];   
}
 
Share this answer
 
v2
Comments
chris085 8-Nov-11 10:25am    
I tried it and after clicking the button the selected file "disappears" from the FileUpload Element. I suppose, because the page is loaded again. Is there any chance to prevent this from happening?
JavaScript
$(function() {
    $("#button1").click(function()
    {
        $("#tb1").val($("#fs1").val());
        return false;
    });
});


For security reason probably the name of the path in my chrome is always "C:\fakepath\".
The name of the file is right though.
sample[^]
 
Share this answer
 

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