HTML DOM Input Button name Property

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>w3wiki</h1>
 
    <h2>HTML DOM Input Button name Property</h2>
 
    <input type="button" id="GFG" onclick="myBeginner()"
        name="Geek_button" value="Submit">
 
    <p id="result"></p>
 
    <script>
        function myBeginner() {
 
            // Return Input Button name Property
            let btnName = document.getElementById("GFG").name;
 
            document.getElementById("result").innerHTML = btnName;
        }
    </script>
</body>
 
</html>


Output: 

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>w3wiki</h1>
 
    <h2>HTML DOM Input Button name Property</h2>
 
    <input type="button" id="GFG" onclick="myBeginner()"
        name="Geek_button" value="Submit">
 
    <p id="result"></p>
 
    <script>
        function myBeginner() {
 
            // Set Input Button name Property
            let btnName = document.getElementById("GFG")
                .name = "Hello Beginner";
 
            document.getElementById("result").innerHTML =
                "Value of name attribute changed to " + btnName;
        }
    </script>
</body>
 
</html>


Output: 

Supported Browsers:

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