Last active
November 18, 2018 21:20
-
-
Save inneroot/c288303bf5b589b61c34fc585b386d32 to your computer and use it in GitHub Desktop.
changing label on bootstrap custom upload file input field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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