Javascript Reference - HTML DOM Input FileUpload name Property








The name attribute from input field upload element identifies form data after it has been submitted to the server.

We can also use name value to reference form data using JavaScript on the client side.

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

Browser Support

name Yes Yes Yes Yes Yes

Syntax

Return the name property.

var v = fileuploadObject.name 

Set the name property.

fileuploadObject.name=name




Property Values

Value Description
name Set the name of the file upload button

Return Value

A String type value representing the name of the file upload button.

Example

The following code shows how to change the name of a file upload button.


<!DOCTYPE html>
<html>
<body>
<!--from   w  ww .j  a  v a 2s  .c o  m-->
A FileUpload object:
<input type="file" id="myFile" name="filename">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myFile").name;
    console.log("The name is: " + x);
}

function change() {
    var x = document.getElementById("myFile").name = "newFileName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

The code above is rendered as follows: