Last active
March 12, 2017 20:28
-
-
Save PauliusKrutkis/9ca9c57ca43da028c8e3972a23275337 to your computer and use it in GitHub Desktop.
jQuery dynamic file input label
This file contains 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
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