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


Similar Reads

HTML | DOM Button name Property
The DOM Button name Property is used to set or return the value of a name attribute of a button element. The name attribute is used to specify the name of the button and it is used to reference form data when it has been submitted by the user. It also refers to the element in the javascript. Syntax: It is used to return the name property.buttonObje
2 min read
HTML | DOM Input Reset name Property
The Input Reset name Property in HTML DOM is used to set or return the value of name attribute of a reset 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 reset name property.resetObject.nameIt is us
2 min read
HTML | DOM Input Datetime name Property
The Input Datetime name property is used for setting or returning the value of the name attribute of a datetime field. The form data which has been submitted to the server can be identified by the name attribute. The name attribute is also used for referencing form data on the client-side using Javascript. Syntax: For returning the name property:da
2 min read
HTML | DOM Input Date name Property
The Input Date name property is used for setting or returning the value of the name attribute of a date field. The form data which has been submitted to the server can be identified by the name attribute. The name attribute is also used for referencing form data on the client-side using JavaScript.Syntax: For returning the name property: inputdateO
2 min read
HTML | DOM Input DatetimeLocal name Property
The Input DatetimeLocal name property is used to set or return the value of the name attribute of a datetimeLocal field. The form data which has been submitted to the server can be identified by the name attribute. The name attribute is also used for referencing form data on the client side using Javascript.Syntax: To return the name property: date
2 min read
HTML | DOM Input Hidden name Property
The Input Hidden name property in HTML DOM is used to set or return the value of the name attribute. The form data which has been submitted to the server can be identified by the name attribute. The name attribute is also used for referencing form data on the client side using JavaScript. Syntax: It returns the Input Hidden name property. hiddenObj
2 min read
HTML | DOM Input Checkbox name Property
The Input Checkbox name property in HTML DOM is used to set or return the value of name attribute of a input checkbox 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 Checkbox name property. checkbox
2 min read
HTML | DOM Input Email name Property
The Input Email name property in HTML DOM is used to set or return the value of name attribute of an email 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 Email name property.emailObject.nameIt is u
2 min read
HTML | DOM Input Password name Property
The DOM Input Password name Property is used to set or return the value of the name attribute of a Password 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 is used to return the name property. passwordObject.nameIt i
2 min read
HTML DOM Input Submit name Property
The Input Submit name Property in HTML DOM is used to set or return the value of name attribute of a submit 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 Submit name property.submitObject.nameIt i
2 min read
Article Tags :