Open In App

HTML DOM Input Search required Property

The Input Search required Property in HTML DOM is used to set or return whether the Input search Field should be filled or not when submitting the form. This property is used to reflect the HTML required attribute. 

Syntax: 



searchObject.required
searchObject.required = true|false

Property Values:

Return Value: It returns a Boolean value which represents that the search Field must be filled or not before submitting the form. 



Example 1: This example illustrates how to return Input search required property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Search required Property
    </title>
</head>
 
<body style="text-align: center;">
 
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Search required Property</h2>
     
    <form id="myGeeks">
        <input type="Search" id="GFG"
            value="GeeksforGeeks" required>
    </form>
    <br><br>
 
    <button onClick="myGeeks()">
        click Here!
    </button>
 
    <p id="result"></p>
 
    <script>
        function myGeeks() {
            let s = document.getElementById("GFG").required;
            document.getElementById("result").innerHTML = s;
        }
    </script>
</body>
 
</html>

Output: 

Example 2: This example illustrates that how to set the input search required Property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Search required Property
    </title>
</head>
 
<body style="text-align: center;">
 
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML DOM Input Search required Property</h2>
     
    <form id="myGeeks">
        <input type="Search" id="GFG"
            placeholder="Type to search.." required>
    </form><br>
 
    <button onClick="myGeeks()">
        Click Here!
    </button>
 
    <p id="result"></p>
 
    <script>
        function myGeeks() {
            let s = document.getElementById(
                "GFG").required = false;
 
            document.getElementById("result")
                .innerHTML = s;
        }
    </script>
</body>
 
</html>

Output: 

Supported Browsers:


Article Tags :