Open In App

HTML DOM Input Search name Property

The Input Search name Property in HTML DOM is used to set or return the value of the name attribute of a search 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: 



searchObject.name
searchObject.name = name

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

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



Example 1: This example returns the Input search name property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Search name Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Search name Property</h2>
     
    <form id="myGeeks">
        <input type="Search" id="test"
            name="myGeeks"
            placeholder="Type to search...">
    </form>
    <br>
 
    <button onclick="myGeeks()">
        click here
    </button>
 
    <p id="result">
    </p>
 
    <script>
        function myGeeks() {
 
            // return input search name property
            let inputName =
                document.getElementById("test").name;
 
            document.getElementById("result")
                  .innerHTML = inputName;
        }
    </script>
</body>
 
</html>

Output: 

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




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Search name Property
    </title>
</head>
 
<body style="text-align: center;">
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Search name Property</h2>
     
    <form id="myGeeks">
        <input type="Search" id="test" name="myGeeks"
            placeholder="Type to search...">
    </form>
    <br>
 
    <button onclick="myGeeks()">
        Click Here
    </button>
 
    <p id="result"></p>
 
    <script>
        function myGeeks() {
 
            // setting input search name property
            let searchName = document.getElementById("test")
                .name = "HelloGeeks";
 
            document.getElementById("result").innerHTML
                = "The value of name attribute changed to "
                + searchName;
        }
    </script>
</body>
 
</html>

Output: 

Supported Browsers:


Article Tags :