Last active
February 5, 2020 03:23
-
-
Save brifiction/05e0d087ef8e54392e95671917b10a4c to your computer and use it in GitHub Desktop.
JQuery - File Upload Text (with Bootstrap)
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
/** | |
* The following block of code is to load all JQuery functions and methods | |
* | |
* | |
* | |
*/ | |
$(document).ready(function () { | |
// load file upload display text function | |
fileUpload(); | |
// file upload display text function | |
function fileUpload() { | |
$('input[type=file]').on('change',function(){ | |
// get the filename | |
var fileName = $(this).val(); | |
// this trim is meant to be robust for all web clients, | |
// trimming full path and only show file itself | |
// for e.g. remove C:\fakepath\ and keep <filename>.<extension> | |
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length); | |
// finally, replace the "Choose a file" label | |
// .custom-file-label is a bootstrap class (example class) | |
$(this).next('.custom-file-label').html(fileName); | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment