Open In App

HTML DOM Input Button name Property

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The Input Button name Property in HTML DOM is used to set or return the value of name attribute of a Button field. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all. 

Syntax: 

  • It returns the Input Button name property.
buttonObject.name
  • It is used to set the Input Button name property.
buttonObject.name = name

Property Values: It contains a single value name which defines the name of the Button field. 

Return Value: It returns a string value which represents the name of the Button field. 

Example 1: This example illustrates how to return Input Button name property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML DOM Input Button name Property</title>
</head>
 
<body style="text-align:center;">
 
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Button name Property</h2>
 
    <input type="button" id="GFG" onclick="myGeeks()"
        name="Geek_button" value="Submit">
 
    <p id="result"></p>
 
    <script>
        function myGeeks() {
 
            // Return Input Button name Property
            let btnName = document.getElementById("GFG").name;
 
            document.getElementById("result").innerHTML = btnName;
        }
    </script>
</body>
 
</html>


Output: 

button-name

Example 2: This example illustrates how to set the Property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML DOM Input Button name Property</title>
</head>
 
<body style="text-align:center;">
 
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Button name Property</h2>
 
    <input type="button" id="GFG" onclick="myGeeks()"
        name="Geek_button" value="Submit">
 
    <p id="result"></p>
 
    <script>
        function myGeeks() {
 
            // Set Input Button name Property
            let btnName = document.getElementById("GFG")
                .name = "Hello Geeks";
 
            document.getElementById("result").innerHTML =
                "Value of name attribute changed to " + btnName;
        }
    </script>
</body>
 
</html>


Output: 

button-name-2

Supported Browsers:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 15
  • Safari 1


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads