Javascript Reference - HTML DOM Input FileUpload value Property








The value property returns the path or the file name selected with the <input type="file"> element.

Browser Support

value Yes Yes Yes Yes Yes

Syntax

var v = fileuploadObject.value 

Return Value

A String type value representing the path or the name of the selected file.





Example

The following code shows how to get the path or the name of the selected file.


<!DOCTYPE html>
<html>
<body>
Select a file to upload:<!-- w w w.  j a  v  a2s  .  com-->
<input type="file" id="myFile" size="50">
<button type="button" onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myFile").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: