RaYell,
You don't need to parse the value returned. document.getElementById("FileUpload1").value returns only the file name with extension.
This was useful for me because I wanted to copy the name of the file to be uploaded to an input box called 'title'. In my application, the uploaded file is renamed to the index generated by the backend database and the title is stored in the database.
Using code like this in a form I can capture the original source upload filename, copy it to a second simple input field. This is so user can provide an alternate upload filename in submit request since the file upload filename is immutable.
Try document.getElementById("FileUpload1").value this value should have a path for a file to be uploaded, just strip all dirs from that value and you will have file name.
RaYell, You don't need to parse the value returned.
document.getElementById("FileUpload1").value
returns only the file name with extension. This was useful for me because I wanted to copy the name of the file to be uploaded to an input box called 'title'. In my application, the uploaded file is renamed to the index generated by the backend database and the title is stored in the database.Using code like this in a form I can capture the original source upload filename, copy it to a second simple input field. This is so user can provide an alternate upload filename in submit request since the file upload filename is immutable.
Try the
value
property, like this:NOTE: It looks like
FileUpload1
is an ASP.Net server-side FileUpload control.If so, you should get its ID using the
ClientID
property, like this:Try
document.getElementById("FileUpload1").value
this value should have a path for a file to be uploaded, just strip all dirs from that value and you will have file name.To get only uploaded file Name use this,
FileUpload1
value contains fake path, that you probably don't want, to avoid that use split and pop last element from your file.In google chrome element.value return the name + the path, but a fake path. Thus, for my case I used the name attribute on the file like below :
this is the call from the page :