I'm using a label tag for file input:
<label for="file" style="cursor: pointer"> <img src="plus.png"><span id="file-text">Select a file</span> </label> Once the user selects a file, I want the text of the label to change to the file name of the selected file, but not the path.
<input type="file" id="file" style="display: none" onchange="document.getElementById('file-text').innerHTML = this.value"/>
Google Chrome is returning
C:\fakepath\filename.jpg
Microsoft Edge is returning the entire correct path of the file on the local file system.
I tried the split function:
onchange="var path = this.value.split('\'); document.getElementById('file-text').innerHTML = 'path[path.length-1]'" But now it is not returning anything. The text doesn't change anymore. Would it be possible to accomplish this in inline script or I'd have to use a separate function?