1

By default,

<input type="file">

shows a button and text that says "no file chosen" and then shows the selected file. I am showing a custom button and thus had to hide the standard button with opacity 0.

How can I show "No file chosen" and show the selected file as well if using a custom button?

Dsrs12
  • 23
  • 2

1 Answers1

2

you can do something like this TO SHOW THE SELECTED FILE:

$(document).ready(function(){    
    $("#file").change(function(){
        getFileName($(this).attr("id"));
    });
});

getFileName = function(id){
    var str = '';
    var files = document.getElementById(id).files;
    for (var i = 0; i < files.length; i++){
        str += files[i].name;
    }
    $("#file-name").text(str);
}

DEMO: http://jsfiddle.net/W2y8D/

Sam Battat
  • 5,725
  • 1
  • 20
  • 29