LearnFast.Ninja

JavaScript get filename from path

This is the JavaScript to get the name of the file you want to upload. In this ASP.NET control you call the function when the text change using onchange event.

Step 1: This is the JavaScript to get the name of the file you want to upload.

function Write_Picture_Name() {

    var Title_Object = document.getElementById('Picture_Title_TextBox');

    var Picture_Name = document.getElementById('Picture_FileUpload').value;

    var FileName = Picture_Name.replace(/^.*[\\\/]/, '')

    var My_Split_Arr = FileName.split(".");

    Title_Object.value = My_Split_Arr[0];

}


Step 2: In this ASP.NET control you call the function when the text change using onchange event.
<asp:FileUpload ID="Picture_FileUpload" runat="server" onchange="Write_Picture_Name()" />

Result:


Tags

javascript

split trim substring path