jQuery <input> get selected file name from input type file

Description

jQuery <input> get selected file name from input type file

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Get Selected File Name</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $('input[type="file"]').change(function(e){
            var fileName = e.target.files[0].name;
            document.getElementById("demo").innerHTML = 
               'The file "' + fileName +  '" has been selected.';
        });//from w ww  .  j  ava  2 s.c o m
    });
</script>
</head>
<body>
    <p id="demo"></p>
    <form>
        <input type="file">
    <p><strong>Note:</strong> 
    Choose any file on your computer and its name will be displayed 
    in an alert dialog box.</p>
    </form>
</body>
</html>



PreviousNext

Related