How to get selected file name from input type file using jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the jQuery change() method

You can use the jQuery change() method to get the file name selected by the HTML form control <input type="file">.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <title>jQuery Get Selected File Name</title>
  • <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  • <script type="text/javascript">
  •     $(document).ready(function(){
  •         $('input[type="file"]').change(function(e){
  •             var fileName = e.target.files[0].name;
  •             alert('The file "' + fileName +  '" has been selected.');
  •         });
  •     });
  • </script>
  • </head>
  • <body>
  •     <form>
  •         <input type="file">
  •     </form>
  • </body>
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.