Display the path or the name of the selected file:
var x = document.getElementById("myFile").value;
Select a file first.
Click button to display the file path of the selected file.
<!DOCTYPE html> <html> <body> Select a file to upload: <input type="file" id="myFile" size="50"> <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w. j a v a2 s.c o m var x = document.getElementById("myFile").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The value property returns the path of the file selected with the <input type="file"> element.
This property might return a fake path.
This property is read-only.
Return Value: | A String, representing the path or the name of the selected file |
---|