I'm trying to have the filename of a chosen file appear in the body of a file picker. This is an Asp.Net Core view. I have the following file input:
<div class="form-group file-upload-wrapper">
<input id="the-file" type="file" name="name" onchange="handleFile()" />
<label class="custom-file-label" for="the-file">Choose a file</label>
</div>
I want the filename to appear in place of the Choose a file
text.
My JS looks like this:
@section Scripts {
<script language="javascript">
function handleFile(file) {
console.log(file);
}
As it currently stands, I'm getting an error:
ReferenceError: handleFile is not defined
My assumption is that handleFile
needs to look something like this:
document.getElementById("the-file").title = file.files[0].name;
Am I on the right lines with this, and why am I getting the above error?
JSFiddle here