HTML | DOM Input FileUpload name Property

The name property is used to set or return the value of the name attribute of a file upload button.
The name attribute is used to identify form data after the submission to the server.

Syntax:

  • Return the name property:
    fileuploadObject.name
  • Set the name property:
    fileuploadObject.name=name

Property Values:



  • name: Specifies the name of the file upload button.

Examples-1: Return “name” property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
  <center>
    <h1>
      Geeks for Geeks
  </h1>
  
    <input type="file"
           id="myFile" 
           name="gfgFile">
  
    <p id="demo"></p>
  
    <button onclick="myFunction()">
        Click
    </button>
  
    <script>
        function myFunction() {
            var x =
                document.getElementById("myFile").name;
            document.getElementById("demo").innerHTML = x;
        }
    </script>
  </center>
</body>
  
</html>

chevron_right


Output:
Before:

After:

Examples-2: Set “name” property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
    <h1>
      Geeks for Geeks
  </h1>
        <input type="file"
               id="myFile">
  
        <p id="demo"></p>
  
        <button onclick="myFunction()">
            Try it
        </button>
  
        <script>
            function myFunction() {
                var x =
                    document.getElementById(
                        "myFile").name = "new name";
  
                document.getElementById("demo").innerHTML = x;
            }
        </script>
    </center>
  
</body>
  
</html>

chevron_right


Output:
Before:

After:

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge 10.0
  • Opera
  • Apple Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.