Open In App

HTML DOM Input Search required Property

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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: 

  • It returns the Input search required property.
searchObject.required
  • It is used to set the Input search required property.
searchObject.required = true|false

Property Values:

  • true: It specifies that the search field must be filled out before submitting the form.
  • false: It is the default value. It specifies that the search field must not be filled out before submitting the form.

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. 

html




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

search-required

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

html




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

search-required-2

Supported Browsers:

  • Google Chrome 5
  • Edge 12
  • Firefox 4
  • Opera 10.6
  • Safari 5


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads