Skip to content

Instantly share code, notes, and snippets.

@inneroot
Last active November 18, 2018 21:20
Show Gist options
  • Save inneroot/c288303bf5b589b61c34fc585b386d32 to your computer and use it in GitHub Desktop.
Save inneroot/c288303bf5b589b61c34fc585b386d32 to your computer and use it in GitHub Desktop.
changing label on bootstrap custom upload file input field
//bootstrap 4 custom upload
//<input type="file" name="fileToUpload" id="fileToUpload" accept=".pdf" class="custom-file-input" onchange="getname(event)">
//<label class="custom-file-label file-upload-info" for="fileToUpload" id="upload_label">Upload PDF</label>
//uploaded filename > label, default label is back on clear;
let deflabel = "Upload File";
if (document.getElementById("upload_label")) deflabel = document.getElementById("upload_label").innerHTML;
function getname(evt){
//console.log(evt);
var filename;
var files = evt.target.files;
if (files.length > 0) {
filename = files[0].name;
} else {
filename = deflabel;
}
document.getElementById("upload_label").innerHTML = filename;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment