Open In App

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: 



buttonObject.name
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. 




<!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: 

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




<!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: 

Supported Browsers:


Article Tags :