Skip to content

Instantly share code, notes, and snippets.

@VermillionOne
Last active January 31, 2019 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VermillionOne/b525cf264bbbcaae8941ae5b5d04cb9e to your computer and use it in GitHub Desktop.
Save VermillionOne/b525cf264bbbcaae8941ae5b5d04cb9e to your computer and use it in GitHub Desktop.
Display filename for custom file upload button
//For updating displayed file name for form file upload inputs - Requires jQuery
$('input[type="file"]').on('change', function(e) {
var fileSelect = e.target,
fileName = e.target.value.split(/\\|\//).pop(),
fileNameTruncated = fileName.length > 20 ? fileName.substr(0, 20) : fileName,
fileNameDisplay = fileSelect.dataset.displayfilename;
$("."+fileNameDisplay).html(fileNameTruncated+"..."+fileName.substr(fileName.length - 4));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment