Skip to content

Instantly share code, notes, and snippets.

@ckahle33
Created May 8, 2014 16:02
Show Gist options
  • Save ckahle33/30a0d693335bd4c35ea7 to your computer and use it in GitHub Desktop.
Save ckahle33/30a0d693335bd4c35ea7 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$('input[type=file]').each(function(){
$(this).parent().append($('<div class="fakefile" />').append($('<img src="/assets/img/file-button.png" alt="File input button" />')));
$(this).on('click', function(){
$('input#input_1_12').click();
})
});
});
@fleeting
Copy link

fleeting commented May 8, 2014

$('#input_1_12').on('change',function(){
  console.log(this.value);
});

@fleeting
Copy link

fleeting commented May 8, 2014

$(document).ready(function() {
  $('input[type=file]').each(function(){
    var input = $(this);
    input.parent().append($('<div class="fakefile '+input.attr('id')+'" />').append($('<img src="/assets/img/file-button.png" alt="File input button" />')));

    $('.fakefile.'+input.attr('id')).on('click', function(){
        input.click();
    });

    input.on('change',function(){
        console.log(this.value.replace("C:\\fakepath\\", ""));
    });
  });
});

@ckahle33
Copy link
Author

ckahle33 commented May 8, 2014

$(document).ready(function() {
  $('input[type=file]').each(function(){
    var input = $(this);
    var fakefile = $('.fakefile.'+input.attr('id'));

    input.parent().append($('<div class="fakefile '+input.attr('id')+'" />').append($('<img src="/assets/img/file-button.png" alt="File input button" />')));


    fakefile.on('click', function(){
        input.click();    
    })

    input.on('change',function(){
        fakefile.text(this.value.replace("C:\\fakepath\\", "  "));
    });

  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment