Javascript Form How to - Get File Upload input field value








Question

We would like to know how to get File Upload input field value.

Answer


<html>
    <body>
    <script language="JavaScript">
    function showname(){<!--from www  .  j a  v  a2  s . c o  m-->
        var  file = document.form1.uploadBox.value ;
        document.form1.filename.value = file ;
    }
    </script>
    <form name="form1">
    Click on browse to choose a file to send.
    <br>
    Click on the Send button to see the full path for the file sent.
    <br><br>
    File to send: <input type="file" name="uploadBox">
    <br><br>
    <input type="button" value="Send" name="get" onClick='showname()'>
    <br><br>
    <input type="text" name="filename" size="40">
    </form>
    </body>
</html>

The code above is rendered as follows: