Javascript DOM HTML Input FileUpload name Property get

Introduction

Get the name of a file upload button:

var x = document.getElementById("myFile").name;

Click the button to display the value of the name attribute of the input element.

View in separate window

<!DOCTYPE html>
<html>
<body>
Select a file to upload:
<input type="file" name="filename" id="myFile">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from w w w  .j  a  va  2 s .co  m*/
  var x = document.getElementById("myFile").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the value of the name attribute of a file upload button.

The name attribute can identify form data after submitting to the server.

Only form elements with a name attribute will be submitted to server.

Property Values

Value Description
name Specifies the name of the file upload button

The name property returns a String representing the name of the file upload button.




PreviousNext

Related