Skip to content

Instantly share code, notes, and snippets.

@PauliusKrutkis
Last active March 12, 2017 20:28
Show Gist options
  • Save PauliusKrutkis/9ca9c57ca43da028c8e3972a23275337 to your computer and use it in GitHub Desktop.
Save PauliusKrutkis/9ca9c57ca43da028c8e3972a23275337 to your computer and use it in GitHub Desktop.
jQuery dynamic file input label
var fileInput = (function($) {
var selector = 'input[type="file"]';
$(selector).on('change', modifyLabel);
function modifyLabel(event) {
var fileName = '';
var id = $(this).attr('id');
var label = $('label[for="'+ id +'"]');
if (this.files && this.files.length > 1)
fileName = this.files.length + ' ' + 'files selected';
else
fileName = event.target.value.split('\\').pop();
if (fileName)
label.text(fileName);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment